-
Notifications
You must be signed in to change notification settings - Fork 764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stripe.Event.Data is too untyped #1387
Comments
Hey @saiichihashimoto, thanks for the feedback! We totally hear you on this. This is something we're investigating in order to provide the best typed experience we can. Currently this is somewhat tricky because you have to consider the API version for the webhook and the SDK version for the types, but I think we can get to a good solution. Going to label this as |
That's fair! I still think some intermediate would be good, event if |
Can we use the API version/SDK version as part of a ternary in here, where if it's the current version onwards we use these new types, but if it's before that, we stick with whatever types we had previously? I have a feeling that new users will use the newest version (hence these types being helpful!) and users of the older versions are already handling the previous types, so adding more strict types might actually be a breaking change. |
Duplicate of #758? |
To keep things keep I'm going to close this as a duplicate. Please track related work in #758. |
Currently, when doing
stripe.webhooks.constructEvent
orstripe.webhooks.constructEventAsync
, the event data (which is what we want) is fully untyped. This forces lots of casting, although the type of the event correlates directly with specific stripe objects. We can actually typeStripe.Event
so that narrowingevent.type
(ie,event.type === "payment_intent.succeeded"
) also narrows theevent.data.object
andevent.data.previous_attributes
(for the previous example,Stripe.PaymentIntent
).I've been using this in my codebase and it's helped tremendously. I haven't been able to use a typescript declaration to override
Stripe.Event
since declarations union with existing definitions, which keepsStripe.Event.Data.Object
asany
no matter what. Can we have the official types use this?The text was updated successfully, but these errors were encountered: