Stripe 20.0.0 Serialization with latest tanstack start
After upgrading to stripe@20.0.0, Iām running into a TypeScript type error when returning a Stripe subscription from a TanStack Start server function.
Stack
@tanstack/start / @tanstack/react-start: 1.139.x
stripe: 20.0.0
typescript: 5.x
Runtime: Node 20
I have a server function roughly like this:
The error I see (shortened) looks like:
Type 'Promise<{ metadata: StripePrice | undefined; stripe: Stripe.Response<Stripe.Subscription>; ... } | null>'
is not assignable to type 'Promise<{ metadata: { ...my custom shape... } | undefined; ... } | null>'.
The types of 'stripe.automatic_tax.liability' are incompatible between these types.
Type 'Liability | null' is not assignable to type '{ account?: string | { ... } | undefined; type: Type; } | null'.
...
It drills all the way down into Stripeās complex nested types (automatic_tax.liability.account, external_accounts, etc.) and complains that my handler return type doesnāt match the expected result type inferred for the server function / Register.
A few notes:
This was compiling fine before upgrading to stripe@20.0.0 & ^1.12 start.
The runtime behavior is fine if I bypass types (e.g. stripe: stripeSub as any), so it seems purely a typing / inference issue.
Questions
Is there a recommended pattern in TanStack Start for returning 3rd-party SDK responses like Stripe.Response<Stripe.Subscription> from server functions?
e.g. should I always expose them as unknown / Record<string, unknown> in my Register / result types and cast on the client?
Is there any change in how Start infers / constrains the server function result type that might make Stripe v20ās updated types incompatible now?
Iām happy to put together a minimal repro if that helps, but wanted to sanity-check first if thereās a known ādonāt return SDK types directly from server functionsā guideline or an example for Stripe v20.
Thanks!