To install, add this gist as a dependency, and @types/stripe-v3 as a dev dependency.
yarn add --dev @types/stripe-v3
yarn add https://gist.github.com/955eafd92692f4ba54d50d447cef6327.git
Or with npm
npm install --save-dev @types/stripe-v3
npm install https://gist.github.com/955eafd92692f4ba54d50d447cef6327.git
Then the following will pass a type check, where previously there would be errors on the import
, window.Stripe
, and typeof Stripe
.
import 'stripe-v3';
function getStripe() {
return window.Stripe;
}
let stripe: typeof Stripe = getStripe();
Be careful if loading stripe asynchronously that you only attempt to use it after the script has loaded. It may be best to do the following and never access it through the global directly.
function getStripe(): typeof Stripe | void {
return window.Stripe;
}