Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net.d.ts pollutes global namespace with DOM types #1326

Closed
martinml opened this issue Jan 11, 2022 · 1 comment
Closed

net.d.ts pollutes global namespace with DOM types #1326

martinml opened this issue Jan 11, 2022 · 1 comment

Comments

@martinml
Copy link

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:

Thoughts? 🤔

@dcr-stripe
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants