Skip to content

Add V2List and V2ListPromise types for v2 list endpoints#2717

Merged
jar-stripe merged 8 commits into
masterfrom
jar/v2-list-types
May 20, 2026
Merged

Add V2List and V2ListPromise types for v2 list endpoints#2717
jar-stripe merged 8 commits into
masterfrom
jar/v2-list-types

Conversation

@jar-stripe
Copy link
Copy Markdown
Contributor

@jar-stripe jar-stripe commented May 15, 2026

Why?

V2 list API responses have a different shape than v1 lists — they return {data, next_page_url, previous_page_url} instead of {object, data, has_more, url}. The SDK was using ApiList<T> (the v1 type) for both, meaning users couldn't access next_page_url or previous_page_url without type assertions.

What?

  • Adds V2List<T> interface with data, next_page_url, and previous_page_url fields
  • Adds V2ListPromise<T> promise wrapper with auto-pagination methods, parallel to ApiListPromise<T>
  • Exports both types from the Stripe namespace
  • Regenerates V2 resource files to return V2ListPromise instead of ApiListPromise
  • Adds tests verifying the v2 list response shape

Note to the reviewer

To avoid introducing a breaking change, V2List temporarily includes the deprecated properties from ApiList (object, has_more, url). This means existing code that expects an ApiList from v2 list endpoints will continue to compile without errors. These properties are not populated at runtime for v2 lists (this was already the case before this PR) and should be removed at the next major release.

See Also

N/A

Changelog

  • Adds V2List and V2ListPromise types to represent API v2 list responses. These types include deprecated fields from the previously returned list shapes. These fields will be removed in the next major release.

V2 list API responses return {data, next_page_url, previous_page_url}
but the SDK typed them as ApiList<T> which has v1-only fields
{object, data, has_more, url}. This adds correct types so users can
access v2 pagination fields without type assertions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
@jar-stripe jar-stripe marked this pull request as ready for review May 15, 2026 23:42
@jar-stripe jar-stripe requested a review from a team as a code owner May 15, 2026 23:42
@jar-stripe jar-stripe requested review from Copilot and mbroshi-stripe and removed request for a team May 15, 2026 23:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds dedicated TypeScript types (V2List<T> and V2ListPromise<T>) modeling the v2 list response shape (data, next_page_url, previous_page_url) so consumers can access pagination URLs without type assertions. Existing v1 ApiList/ApiListPromise are unchanged. Generated v2 resource files are left on ApiListPromise pending a follow-up codegen update.

Changes:

  • Define V2List<T> and V2ListPromise<T> in src/lib.ts parallel to the v1 equivalents.
  • Re-export both types from the Stripe namespace in src/stripe.core.ts.
  • Add tests in test/resources/V2/Core/Events.spec.js asserting the new response shape (including null pagination URLs).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/lib.ts Adds V2List<T> interface and V2ListPromise<T> async iterator/promise type.
src/stripe.core.ts Imports and re-exports the new types from the Stripe namespace.
test/resources/V2/Core/Events.spec.js Adds two tests verifying v2 list shape and null pagination URLs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@mbroshi-stripe mbroshi-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, but adding @prathmesh-stripe in case there is some export edge case I'm not aware of (I know we've seen issues with, e.g., Stripe.Decimal recently).

@jar-stripe jar-stripe requested a review from xavdid May 20, 2026 01:11
Copy link
Copy Markdown
Member

@xavdid xavdid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave to prathmesh for final approval since he has the most context. Approach looks good though.

One thing to add: a block in typescriptTest that verifies the types are correct. I believe these runtime tests would pass today, since the API shape hasn't changed.

Lastly, this is definitely a breaking change (and the PR title should reflect that). If we're settled on doing an out-of-band major release for it, we should write the migration docs and things.

Comment thread src/lib.ts
Comment thread src/stripe.core.ts
checks; this enables type support for v2 pagination urls without
changing behavior around incorrect v1 list fields
@jar-stripe jar-stripe requested a review from xavdid May 20, 2026 16:59
fixerd issues in test code and white space in comments
into V2List; marked them deprecated and moved the TODO to remove them
Copy link
Copy Markdown
Member

@xavdid xavdid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving to unblock- I think the shim will work.

Still should add the typescript test mentioned above- we rely on those for regression checking!

Comment thread src/lib.ts
Comment thread test/resources/V2/Core/Events.spec.js
@jar-stripe jar-stripe merged commit 6daca1e into master May 20, 2026
10 checks passed
@jar-stripe jar-stripe deleted the jar/v2-list-types branch May 20, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants