user967451
user967451

Reputation:

What type to use for the `CardElement` in typescript for `@stripe/react-stripe-js` package?

I can't for the life of me figure out what type I should be using for this import:

import { CardElement } from '@stripe/react-stripe-js';

For the stripe and elements props you drill from the consumer and for the optional token object for example I used these types correctly:

import { Stripe, StripeElements, CreateTokenCardData } from '@stripe/stripe-js';

but for CardElement I just can't find the right type to use. I looked at the definition files inside node_modules/@stripe/stripe-js as well as node_modules/@stripe/react-stripe-js but no luck.

Does anyone know?

Upvotes: 0

Views: 2148

Answers (1)

ttmarek
ttmarek

Reputation: 3260

...but for CardElement I just can't find the right type to use.

The type you're looking for is likely the CardElementComponent type, which you can import along with the component as follows:

import { CardElement, CardElementComponent } from "@stripe/react-stripe-js";

You can reference the type definition, along with the type definitions of all the other components included in @stripe/react-stripe-js in this file here:

https://github.com/stripe/react-stripe-js/blob/e13fae556b1a667a5dfa1130c00d5ec4c2bc154e/src/types/index.ts#L78

Upvotes: 1

Related Questions