Skip to content
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

[BUG]: confirmSetup overloads are incorrectly throwing errors #673

Open
TheDutchCoder opened this issue Oct 22, 2024 · 0 comments
Open

[BUG]: confirmSetup overloads are incorrectly throwing errors #673

TheDutchCoder opened this issue Oct 22, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@TheDutchCoder
Copy link

TheDutchCoder commented Oct 22, 2024

What happened?

When using confirmSetup in TypeScript, with, for example, options like these, TS will throw errors for missing properties like clientSecret, even though this is only required in a few of the overloads. It seems to have trouble selecting the proper one.

const stripeArguments = {
  redirect: 'if_required',
  elements: (stripeElements.value as StripeElements),
  confirmParams: {
    return_url: returnUrl,
  },
}

// Should not throw an error.
stripe?.confirmSetup(stripeArguments)

Additionally, the type for redirect is set to "always", which is one of the options, but doesn't include "if_required".
it looks like it just uses the last overload at all times, which has this signature:

confirmSetup(options: {
  elements?: StripeElements;
  clientSecret: string;
  confirmParams: setupIntents.ConfirmSetupData;
  redirect?: 'always';
}): Promise<never | {error: StripeError}>;

The only workaround I have found is by creating a custom type to force the right overload to be selected:

type OverloadOptions = {
  elements: StripeElements
  confirmParams?: Partial<ConfirmSetupData>
  redirect: 'if_required'
}

const stripeArguments: OverloadOptions = {
  redirect: 'if_required',
  elements: (stripeElements.value as StripeElements),
  confirmParams: {
    return_url: returnUrl,
  },
}

Environment

Chrome 130 on MacOS 15.0.1

Reproduction

No response

@TheDutchCoder TheDutchCoder added the bug Something isn't working label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant