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
Typings polutes global space with DOM types #1285
Comments
yo1dog
added a commit
to yo1dog/node-fetch
that referenced
this issue
Sep 13, 2021
yo1dog
added a commit
to yo1dog/node-fetch
that referenced
this issue
Sep 13, 2021
4 tasks
Pull request: #1287 |
+1 for this one. It's really annoying! |
jimmywarting
pushed a commit
that referenced
this issue
Jul 13, 2022
The release is available on: Your semantic-release bot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Same issue superagent had with their typings: DefinitelyTyped/DefinitelyTyped#41425 (comment)
The
dom
reference triple-slash directive in/@types/index.d.ts
causes all DOM types to be included in the global ambient declarations which breaks type checking.node-fetch/@types/index.d.ts
Line 2 in 9cd2e43
See: https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html#-reference-lib-
This means that Node.js projects that import
node-fetch
can reference DOM global types and values (window
,document
,Element
,ChildNode
, etc.) without typing errors.This line don't seem to be needed as nothing from the DOM library is referenced. Can we just delete this line? I tried doing so, and TypeScript had no complaints.
Reproduction:
Simple TypeScript project that does NOT include DOM library.
Attempting to access the window global throws a type error as expected.
Same as above except we import node-fetch and the type error disappears unexpectedly.
TypeScript reports the DOM library is being loaded due to a reference in node-fetch's type declaration file.
As you can see, simply importing
node-fetch
breaks type checking becauselib.dom.d.ts
is loaded due to the reference fromnode-fetch/@types/index.d.ts
. This can also be observed in VSCode where DOM types are shown in autocomplete suggestions.The text was updated successfully, but these errors were encountered: