stripe-node: TypeScript types are invalid when expanding responses

Describe the bug

When expanding responses as per the documentation here, the return types for various Stripe methods are not updated to accurately reflect the modified responses.

To Reproduce

const stripeCustomer = await stripe.customers.retrieve(
  stripeCustomerId,
  {
    expand: ['subscriptions'],
  },
)

Expected behavior

The returned data does indeed contain a nested subscriptions object:

"subscriptions": {
  "object": "list",
  "data": [...]
}

However, the TypeScript types do not declare this at all.

Code snippets

No response

OS

macOS

Node version

Node v16.4.2

Library version

stripe-node v10.8.0

API version

2022-08-01

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

As a compromise, I wonder if we could get types for the unexpanded variant of each response?

This would add some bloat to the library, but you could probably accomplish it via “normal” function overloads, ie.

update(
  id: string,
  params?: Omit<SubscriptionUpdateParams, 'expand'> & { expand: never },
  options?: RequestOptions
): Promise<Stripe.UnexpandedSubscription>;
update(
  id: string,
  params?: SubscriptionUpdateParams,
  options?: RequestOptions
): Promise<Stripe.Subscription>;

(The second overload is the “normal” one that we have in the library today)

This would be a huge improvement for many common use-cases, as the current union types are exceedingly difficult to work with.