-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Implement provide/inject & use vite v6 #38
base: main
Are you sure you want to change the base?
Conversation
src/stripe-elements.ts
Outdated
@@ -62,10 +139,8 @@ export const createElement = ( | |||
if (!elementType) { | |||
throw new Error(ERRORS.ELEMENT_TYPE_NOT_DEFINED) | |||
} | |||
const element = elements.create(elementType, options) | |||
return element | |||
return elements.create(elementType, options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey folks 👋
this is Vue equivalent of react-stripe-js
I'm preparing a new major version but this typescript overload issue has been a blocker. I'm trying to type a generic function that creates Stripe Element using @stripe/stripe-js
Overloads of elements.create()
are so specific I'm having hard time.
- tried StripeElementType (union)
- tried mapping element types and options
StripeElementOptionsMap
- tried generics
I'd like to avoid maintaining such map types, because stripe-js as a better source of truth for these types.
How do you recommend typing functions with such specific overloads?
@pololi-stripe
@bdaily-stripe
@alexlande-stripe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example using generics, trying to narrow down elementType
and options
export type StripeElementOptionsMap = {
address: StripeAddressElementOptions
affirmMessage: StripeAffirmMessageElementOptions
afterpayClearpayMessage: StripeAfterpayClearpayMessageElementOptions
auBankAccount: StripeAuBankAccountElementOptions
card: StripeCardElementOptions
cardCvc: StripeCardCvcElementOptions
cardExpiry: StripeCardExpiryElementOptions
...
}
export const createElement = <T extends keyof StripeElementOptionsMap>(
elements: StripeElements,
elementType: T,
options?: StripeElementOptionsMap[T],
) => {
try {
if (!elements) {
throw new Error(ERRORS.ELEMENTS_NOT_DEFINED)
}
if (!elementType) {
throw new Error(ERRORS.ELEMENT_TYPE_NOT_DEFINED)
}
const element = elements.create(elementType, options)
return element
} catch (error) {
console.error(error)
}
}
Breaking changes
Features
Payment Element by default
As Stripe evolves, now Payment is the recommended flow. It used to be Card. To let you upgrade without breaking the code: payment for new starters, card for legacy.
Better examples
Fixes
Added missing event listeners for
loaderror
loaderstart
Screenshot