@types/stripe-react-elements package and had problems.Definitions by: in index.d.ts) so they can respond.May open a pull request for this when I get time - but @types/stripe-react-elements defines the props for StripeProvider as:
interface StripeProviderProps {
apiKey: string;
}
When in reality (see docs here) it can also accept a Stripe.js instance in place of apiKey when loaded asynchronously.
I'm guessing the answer is to make it a union of { apiKey: string } | { stripe: StripeJsInstance } but I'd have to do some digging to see if there's a good type definition of the latter...
I contributed to these types for a client I'm no longer working with and I'm not fully up to date with the stripe library, but what you propose sounds reasonable. If you create a pull request I'll be happy to review it, just ensure that you have tests for either scenario.
@dan-j @dylanpyle
For StripeJsInstance which you've suggested, I think we can reference stripe.Stripe from @types/stripe-v3
Kindly review this and see if it makes sense.
Cheers 馃槃
I realised the type definition of stripe.Stripe.createToken doesn't quite fit with react-stripe-elements.createToken. So will be reverting back to StripeProps.
So only change now is adding props.stripe to StripeProvider.
I'm not sure if this is related, but should the StripeProps interface be exported as well?
I ask this as I'm trying to use injectStripe in a typescript application. I am getting compiler error on the component that I've used injectStripe on saying that there is no property stripe on my state object for my component.
Related issue, I'm using:
<StripeProvider stripe={instance}>
My IDE is complaining that:
Element StripeProvider doesn't have required attribute apiKey
But you don't need both props (stripe and apiKey) at the same time.
@nabrahamson did you figure out a workaround? I just hit the same thing.
Checking the type:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-stripe-elements/index.d.ts#L36
My issue was that I was passing apiKey as string | undefined. Checking that apiKey is set and therefore passing apiKey as string did the trick.
Most helpful comment
I'm not sure if this is related, but should the StripeProps interface be exported as well?
I ask this as I'm trying to use injectStripe in a typescript application. I am getting compiler error on the component that I've used injectStripe on saying that there is no property stripe on my state object for my component.