Skip to content

Commit bfed57c

Browse files
committed
fix: resolve overload issues
1 parent 5ee6ad3 commit bfed57c

File tree

2 files changed

+73
-15
lines changed

2 files changed

+73
-15
lines changed

src/components/StripeElement.vue

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,21 @@ import type { StripeElementType, StripeElements } from "@stripe/stripe-js"
77
import type { Ref } from "vue"
88
import {
99
computed,
10-
defineEmits,
1110
inject,
1211
onBeforeUnmount,
1312
onMounted,
1413
ref,
1514
toRefs,
1615
watch,
1716
} from "vue"
18-
import type { StripeElementOptionsMap } from "../stripe-elements"
17+
import type { StripeElementOptions } from "../stripe-elements"
1918
import { createElement } from "../stripe-elements"
2019
21-
interface Props {
20+
const props = defineProps<{
2221
type?: StripeElementType
2322
elements?: StripeElements
24-
options?: StripeElementOptionsMap[StripeElementType]
25-
}
26-
27-
const props = defineProps<Props>()
28-
23+
options?: StripeElementOptions
24+
}>()
2925
const emit = defineEmits(eventTypes)
3026
const { type, elements, options } = toRefs(props)
3127
@@ -86,7 +82,8 @@ onBeforeUnmount(() => {
8682
8783
watch(options, () => {
8884
if (options.value && stripeElement.value && "update" in stripeElement.value) {
89-
stripeElement.value.update(options.value)
85+
// biome-ignore lint/suspicious/noExplicitAny: update option ts overload is too specific
86+
stripeElement.value.update(options.value as any)
9087
}
9188
})
9289

src/stripe-elements.ts

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,58 @@
11
import type {
22
Stripe,
3+
StripeAddressElement,
34
StripeAddressElementOptions,
5+
StripeAffirmMessageElement,
46
StripeAffirmMessageElementOptions,
7+
StripeAfterpayClearpayMessageElement,
58
StripeAfterpayClearpayMessageElementOptions,
9+
StripeAuBankAccountElement,
610
StripeAuBankAccountElementOptions,
11+
StripeCardCvcElement,
712
StripeCardCvcElementOptions,
13+
StripeCardElement,
814
StripeCardElementOptions,
15+
StripeCardExpiryElement,
916
StripeCardExpiryElementOptions,
17+
StripeCardNumberElement,
1018
StripeCardNumberElementOptions,
1119
StripeConstructorOptions,
20+
StripeCurrencySelectorElement,
1221
StripeElementType,
1322
StripeElements,
1423
StripeElementsOptions,
1524
StripeElementsOptionsClientSecret,
1625
StripeElementsOptionsMode,
26+
StripeEpsBankElement,
1727
StripeEpsBankElementOptions,
28+
StripeExpressCheckoutElement,
1829
StripeExpressCheckoutElementOptions,
30+
StripeFpxBankElement,
1931
StripeFpxBankElementOptions,
32+
StripeIbanElement,
2033
StripeIbanElementOptions,
34+
StripeIdealBankElement,
2135
StripeIdealBankElementOptions,
36+
StripeIssuingCardCopyButtonElement,
2237
StripeIssuingCardCopyButtonElementOptions,
38+
StripeIssuingCardCvcDisplayElement,
2339
StripeIssuingCardCvcDisplayElementOptions,
40+
StripeIssuingCardExpiryDisplayElement,
2441
StripeIssuingCardExpiryDisplayElementOptions,
42+
StripeIssuingCardNumberDisplayElement,
2543
StripeIssuingCardNumberDisplayElementOptions,
44+
StripeIssuingCardPinDisplayElement,
2645
StripeIssuingCardPinDisplayElementOptions,
46+
StripeLinkAuthenticationElement,
47+
StripeP24BankElement,
2748
StripeP24BankElementOptions,
49+
StripePaymentElement,
2850
StripePaymentElementOptions,
51+
StripePaymentMethodMessagingElement,
2952
StripePaymentMethodMessagingElementOptions,
53+
StripePaymentRequestButtonElement,
3054
StripePaymentRequestButtonElementOptions,
55+
StripeShippingAddressElement,
3156
StripeShippingAddressElementOptions,
3257
} from "@stripe/stripe-js"
3358

@@ -65,7 +90,7 @@ export type StripeElementOptionsMap = {
6590
cardCvc: StripeCardCvcElementOptions
6691
cardExpiry: StripeCardExpiryElementOptions
6792
cardNumber: StripeCardNumberElementOptions
68-
currencySelector: undefined
93+
currencySelector?: undefined
6994
epsBank: StripeEpsBankElementOptions
7095
expressCheckout: StripeExpressCheckoutElementOptions
7196
fpxBank: StripeFpxBankElementOptions
@@ -76,14 +101,42 @@ export type StripeElementOptionsMap = {
76101
issuingCardExpiryDisplay: StripeIssuingCardExpiryDisplayElementOptions
77102
issuingCardNumberDisplay: StripeIssuingCardNumberDisplayElementOptions
78103
issuingCardPinDisplay: StripeIssuingCardPinDisplayElementOptions
79-
linkAuthentication: undefined
104+
linkAuthentication?: undefined
80105
p24Bank: StripeP24BankElementOptions
81106
payment: StripePaymentElementOptions
82107
paymentMethodMessaging: StripePaymentMethodMessagingElementOptions
83108
paymentRequestButton: StripePaymentRequestButtonElementOptions
84109
shippingAddress: StripeShippingAddressElementOptions
85110
}
86111

112+
export type StripeElementMap = {
113+
address: StripeAddressElement
114+
affirmMessage: StripeAffirmMessageElement
115+
afterpayClearpayMessage: StripeAfterpayClearpayMessageElement
116+
auBankAccount: StripeAuBankAccountElement
117+
card: StripeCardElement
118+
cardCvc: StripeCardCvcElement
119+
cardExpiry: StripeCardExpiryElement
120+
cardNumber: StripeCardNumberElement
121+
currencySelector: StripeCurrencySelectorElement
122+
epsBank: StripeEpsBankElement
123+
expressCheckout: StripeExpressCheckoutElement
124+
fpxBank: StripeFpxBankElement
125+
iban: StripeIbanElement
126+
idealBank: StripeIdealBankElement
127+
issuingCardCopyButton: StripeIssuingCardCopyButtonElement
128+
issuingCardCvcDisplay: StripeIssuingCardCvcDisplayElement
129+
issuingCardExpiryDisplay: StripeIssuingCardExpiryDisplayElement
130+
issuingCardNumberDisplay: StripeIssuingCardNumberDisplayElement
131+
issuingCardPinDisplay: StripeIssuingCardPinDisplayElement
132+
linkAuthentication: StripeLinkAuthenticationElement
133+
p24Bank: StripeP24BankElement
134+
payment: StripePaymentElement
135+
paymentMethodMessaging: StripePaymentMethodMessagingElement
136+
paymentRequestButton: StripePaymentRequestButtonElement
137+
shippingAddress: StripeShippingAddressElement
138+
}
139+
87140
export const ERRORS = {
88141
STRIPE_NOT_LOADED:
89142
"Stripe is not loaded. Include it as script or load using loadStripe method of @stripe/stripe-js",
@@ -127,10 +180,15 @@ export const createElements = (
127180
}
128181
}
129182

130-
export const createElement = (
183+
type CreateFn = <T extends StripeElementType>(
184+
elementType: T,
185+
options?: StripeElementOptionsMap[T],
186+
) => StripeElementMap[T]
187+
188+
export const createElement = <T extends StripeElementType>(
131189
elements: StripeElements,
132-
elementType: StripeElementType,
133-
options?: StripeElementOptionsMap[StripeElementType],
190+
elementType: T,
191+
options?: StripeElementOptionsMap[T],
134192
) => {
135193
try {
136194
if (!elements) {
@@ -139,7 +197,10 @@ export const createElement = (
139197
if (!elementType) {
140198
throw new Error(ERRORS.ELEMENT_TYPE_NOT_DEFINED)
141199
}
142-
return elements.create(elementType, options)
200+
// Type assertion to bypass the overloads issue
201+
const create: CreateFn = elements.create.bind(elements) as CreateFn
202+
const element = create(elementType, options)
203+
return element
143204
} catch (error) {
144205
console.error(error)
145206
}

0 commit comments

Comments
 (0)