stripe-node icon indicating copy to clipboard operation
stripe-node copied to clipboard

Exported type of Stripe.PaymentIntent.NextAction.type is too broad (string)

Open boiseiben opened this issue 3 months ago • 4 comments

Describe the bug

Though documentation seems to be on the light side, it looks like the intent is to allow indexing of the next_action object with the type parameter, in a statement like this: payment_intent.next_action[payment_intent.next_action.type]

I think changing string to keyof NextAction on this line would fix this, probably also needing something similar in Refunds.d.ts and SetupIntent.d.ts, but if those files are built from other source, the other source would need to be updated.

To Reproduce

Try to write a statement like payment_intent.next_action[payment_intent.next_action.type] in a TypeScript project.

Observe error TS7053:

expression of type 'string' can't be used to index type 'NextAction'. No index signature with a parameter of type 'string' was found on type 'NextAction'.

Expected behavior

Either no error on a line like that, or better documentation about the possible values of NextAction.type.

OS

Win11

Node version

Node v24.2.0

Library version

19.2.0-beta.1

API version

2025-09-30.preview

Additional context

It would also be useful to add a component to the React library that parses this data and presents it to the user.

boiseiben avatar Oct 21 '25 20:10 boiseiben

Yeah, that's a great suggestion! We'll look into what fixing it would take. Because you're right, there are always wider implications 😅

xavdid-stripe avatar Oct 27 '25 21:10 xavdid-stripe

I think it's just using a narrower type declaration than string on the cited line(s), and I am patching locally with that modification. If the narrower type causes something to stop compiling without warnings/errors, that is probably a useful and intended effect because it's helping eliminate runtime errors about a key not existing, by making sure the checks are done properly in advance of a call.

boiseiben avatar Oct 27 '25 21:10 boiseiben

For sure, I agree with it in general. It's just that what seems like a small fix can sometimes be more complex because of the way our code generation works.

xavdid-stripe avatar Oct 27 '25 21:10 xavdid-stripe

Just as a note for contrast, the payment_method.type field is typed more strictly, to an enumerated subset of keys of the object. However, within setup_attempt.payment_method_details, the type field is also an overly broad string, despite a very similar documentation note that "An additional hash is included on payment_method_details with a name matching this value."

boiseiben avatar Nov 03 '25 20:11 boiseiben