Definitelytyped: @types/stripe-react-elements missing `stripe` prop on StripeProvider

Created on 19 Jan 2018  路  7Comments  路  Source: DefinitelyTyped/DefinitelyTyped

  • [x] I tried using the @types/stripe-react-elements package and had problems.
  • [x] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • [x] I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • [x] [Mention](https://github.com/blog/821-mention-somebody-they-re-notified) the authors (see Definitions by: in index.d.ts) so they can respond.

    • Authors: @dan-j @santiagodoldan @sonnysangha


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...

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.

All 7 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jrmcdona picture jrmcdona  路  3Comments

ArtemZag picture ArtemZag  路  3Comments

alisabzevari picture alisabzevari  路  3Comments

demisx picture demisx  路  3Comments

JWT
svipas picture svipas  路  3Comments