You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since #1273 was merged, importing stripe-node in TypeScript makes all the types of the DOM present in the global namespace, because of the /// <reference lib="dom" /> line in net.d.ts.
This can hide bugs from the TypeScript compiler that now can only be caught at runtime. For example:
# some preparing
mkdir stripe-test
cd stripe-test
npm init --yes
npm i stripe
npm i typescript
echo 'document.write()' > test.ts
npx tsc --lib es2020 test.ts # code does not compile, which is correct!
# but now let's import stripe-node...
echo 'import { Stripe } from "stripe"; document.write()' > test.ts
npx tsc --lib es2020 test.ts
# it now compiled! but of course crashes on runtime since node doesn't have a DOM:
node test.js # ReferenceError: document is not defined
I am not familiar with the internals of stripe-node so I don't know how this could be fixed, but in other projects where something like this has happened it has been suggested that a solution would be copypasting the DOM definitions directly:
Thanks for the report! #1327 should address this - we opted for removing the types on these as unfortunately copying over the DOM definitions was a significant undertaking that would be prone to errors down the line.
Since #1273 was merged, importing
stripe-node
in TypeScript makes all the types of the DOM present in the global namespace, because of the/// <reference lib="dom" />
line innet.d.ts
.This can hide bugs from the TypeScript compiler that now can only be caught at runtime. For example:
I am not familiar with the internals of
stripe-node
so I don't know how this could be fixed, but in other projects where something like this has happened it has been suggested that a solution would be copypasting the DOM definitions directly:lib: ['dom']
, which is non-ideal for non-browser environments and not documented apollographql/apollo-client#6376Thoughts? 🤔
The text was updated successfully, but these errors were encountered: