-
Notifications
You must be signed in to change notification settings - Fork 748
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
Incomplete Typescript Types #1999
Labels
Comments
Here is some typescript I was playing around with to provide an example on how this can be achieved type StripeCustomer = { // this type already exists
email: string;
id: number;
// ...
};
type CheckoutSession = { // this type already exists
customer: string | StripeCustomer;
// ...
};
type ValidKeys = keyof CheckoutSession;
function retrieve(options?: { expand?: ValidKeys[] }): CheckoutSession { // fix this function to return correctly
if (options?.expand && options.expand.includes('customer')) {
return { customer: { email: "foo@example.com", id: 1234 } };
} else {
return { customer: "default string value" };
}
}
// Examples
const objWithStringCustomer = retrieve(); // { customer: "default string value" }
const objWithObjectCustomer = retrieve({ expand: ['customer'] }); // { customer: { email: "foo@example.com", id:1234 } } |
Duplicate of #1556. In short, we tried to prototype what full typing support would look like, and it led to extreme complications of the SDK types. |
Just chiming in, this is the solution I came up with for an expanded product on a price: if (typeof price.product === 'object' && !price.product?.deleted) {
// access price.product safely
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
The types for retrieving are incomplete.
(checkout.sessions.retrieve, some.function.retrieve, ...etc)
the return type gives customers as optionals when it needs to depend on the options passed in as params. if the customer section is not included in the expand param, the return type for customer should not be "string | stripe.customer". it should just be string. the same thing for all the other extendable keys.
it makes it very difficult to use typescript without typecasting which can cause problems if I do them incorrectly.
Can the types be fixed to give correct types?
here, since 'subscription' is expanded, the type should be
stripe.subscription | null
, notstring | stripe.subscription | null
Ubuntu
20
14.11
2023-10-16
The text was updated successfully, but these errors were encountered: