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

Fix TypeScript definitions for `tiers` in `Plan`

Open mac-cain13 opened this issue 3 years ago • 1 comments

This PR adds null to type definition of tiers in Plan and removes the ability for tiers to be undefined.

Issue

The type definition for the payload delivered for Stripe webhook for event invoice.payment_succeeded seems to be incorrect. I copied the JSON request to my endpoint from the dashboard into an unit test, but casting data.object of this event to the Stripe.Invoice types fails.

This is because Stripe.Invoice defines lines.data.plan.tiers to be either undefined or an array of Plan.Tiers, in the payload of the invoice.payment_succeeded the tiers field in plan is set to null. Note that the payload of price (which also contains the tiers?: Array<Plan.Tier> definition is correctly undefined and produces no issues.

Solution

I propose to make the type definition match to reality by adding the option to be null to the tiers field of Plan. Was thinking of also removing the ability to be undefined in Plan, but I cannot be 100% sure it is always the case that this field is null when there are no tiers in use.

mac-cain13 avatar Aug 11 '21 20:08 mac-cain13

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Aug 11 '21 20:08 CLAassistant

I apologize for the extremely delayed response.

I suspect what you are seeing is the pre 2020-08-27 API version behavior. The type definition is correct in relation to the latest API version.

pakrym-stripe avatar Feb 06 '23 20:02 pakrym-stripe