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
The current types include globals that don't exist in Node #285
Comments
Despite this reference in I'm not sure how to explain this, but it seems that this line might be ignored for types included in a package (versus loading from DefinitelyTyped)? |
@amacneil thank you for providing those details. Sadly I'm currently not aware how to improve/resolve this issue without completely changing how we define those types. |
I agree, it is surprising behavior. I created a repro here: https://github.com/amacneil/xmldom-types-repro You can see the build output here: https://github.com/amacneil/xmldom-types-repro/actions/runs/1163442338 I found that for both the old and new version, if the package imports However, if I don't know why this behavior happens, but at least this proves what is happening. |
One thing worth calling out is that typescript default behavior is to load all the type definitions in the @types folder. It considers the @types folder a typeRoot (https://www.typescriptlang.org/tsconfig). This might contribute to different behavior for triple slash reference directives. |
Since we have not heard anybody having issue with this for quite a while, I will close this issue now. If this is still an issue for you, please leave a comment here and I will reopen it. |
Having issues with this. When importing Here is the relevant TypeScript issue: microsoft/TypeScript#33111 A common solution other library maintainers have landed on is to just vendor the necessary DOM types into their projects, for example: sindresorhus/is#93 An ugly workaround is to import the JS file directly, bypassing the type declarations: import { DOMParser } from "@xmldom/xmldom/lib/index" But then you won't get the typings. |
@tjhorner thx for reporting this. |
I encountered this issue myself. Obviously the types in |
This is a "copy" of DefinitelyTyped/DefinitelyTyped#49953
since we copied the type definitions from DefinitlyTyped to fix the (types) regression introduced in #278.
The current types reference TypeScript's DOM typings with
/// <reference lib="dom" />
. This causes any module that imports xmldom to get the entire DOM typings, including globals likedocument
.With those globals defined we lose errors when accidentally referencing them, which can obviously cause crashes.
It'd be great if we would only provide the types that we use and export, like
DOMImplementation
,Document
,Node
, etc.Related "main thread": #191
The text was updated successfully, but these errors were encountered: