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

xmldom types include globals that don't exist in Node #49953

Open
5 tasks done
justinfagnani opened this issue Dec 4, 2020 · 6 comments
Open
5 tasks done

xmldom types include globals that don't exist in Node #49953

justinfagnani opened this issue Dec 4, 2020 · 6 comments

Comments

@justinfagnani
Copy link

The xmldom 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 like document.

With those globals defined we lose errors when accidentally referencing them, which can obviously cause crashes.

It'd be great if xmldom could pick off only the DOM types that it uses and exports, like DOMImplementation, Document, Node, etc. I'm not sure if this is possible with lib.dom.d.ts

@karfau
Copy link
Contributor

karfau commented Dec 4, 2020

@justinfagnani thank you for reporting the issue!

Can you try something to see if it works as I understood the docs:
In the project (is it a public one?) after yarn/npm install go to
node_modules/@types/xmldom/index.d.ts
and apply the following change:

- /// <reference lib="dom" />
+ /// <reference types="dom" />

and check if your problem is solved.
(If that works I will provide a PR.)

Thank you

@justinfagnani
Copy link
Author

@Karfu that doesn't work since types looks in the places where userland types are (@types, the types config, etc.) "dom" is a built-in library like "es2020".

@markdon
Copy link

markdon commented Mar 1, 2021

Maybe the built in dom types shouldn't be used at all. xmldom doesn't implement the entire interface for the built in Document and Element types. It's at least missing the querySelector functions.

@karfau
Copy link
Contributor

karfau commented Mar 6, 2021

I think you are right. And I think the effort to either manually write or generate the types that are actually supported is not to big.
I might even be able to support the integration of the types into the actual package.
But the resources in the xmldom project are really limited currently.
Any support would be useful.

@brodybits
Copy link

FYI updates are now published as @xmldom/xmldom, which includes the types as of version 0.7.1, as discussed here: xmldom/xmldom#271

We have discussion of the @xmldom/xmldom types here: xmldom/xmldom#191, xmldom/xmldom#285

@ab-pm
Copy link
Contributor

ab-pm commented Feb 6, 2024

Related issues for other libs: #55382, node-fetch/node-fetch#1285

Ideas to fix this issue properly: microsoft/TypeScript-DOM-lib-generator#1207, microsoft/TypeScript#33111, microsoft/TypeScript#43990

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

5 participants