Skip to content

Instantly share code, notes, and snippets.

@brigand
Last active November 14, 2019 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brigand/955eafd92692f4ba54d50d447cef6327 to your computer and use it in GitHub Desktop.
Save brigand/955eafd92692f4ba54d50d447cef6327 to your computer and use it in GitHub Desktop.
A gist npm package for using @types/stripe-v3

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;
}
{
"name": "stripe-v3",
"version": "0.1.0"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment