We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Currently, the type of Document.documentElement is HTMLElement:
Document.documentElement
HTMLElement
https://github.com/Microsoft/TypeScript/blob/4d74f67325d305f52a2b00b4f30b5a4f3210c649/lib/lib.dom.d.ts#L4124
But it is possible for a Document’s documentElement property to be of type SVGSVGElement which is not a subtype of HTMLElement:
Document
documentElement
SVGSVGElement
Try to run the following code:
const d = (new DOMParser()).parseFromString('<svg xmlns="http://www.w3.org/2000/svg"></svg>', 'image/svg+xml'); const k = (d instanceof Document) && (d.documentElement instanceof SVGSVGElement);
the value of k should be true.
k
true
Also, why isn’t there a SVGDocument in TypeScript?
SVGDocument
The text was updated successfully, but these errors were encountered:
Probably because it's usually used with HTML and not anything else that isn't HTML. And HTML should have the <html> tag as the root element.
<html>
You can pretty much have any XML tag be the documentElement.
Might be oversight. Might be deliberate after weighing correctness vs. ease of the "usual" use case
Sorry, something went wrong.
This can probably be subsumed by #4689. Although originally about parentElement, discussion in that ticket includes documentElement as well.
parentElement
AFAIK we know this and override the Element base type with HTMLElement because most usages are with the DOM's document.
Element
DOM
document.documentElement
null
I think that documentElement should be just Element. Then it can be used as HTMLElement or SVGSVGElement.
No branches or pull requests
Currently, the type of
Document.documentElement
isHTMLElement
:https://github.com/Microsoft/TypeScript/blob/4d74f67325d305f52a2b00b4f30b5a4f3210c649/lib/lib.dom.d.ts#L4124
But it is possible for a
Document
’sdocumentElement
property to be of typeSVGSVGElement
which is not a subtype ofHTMLElement
:Try to run the following code:
the value of
k
should betrue
.Also, why isn’t there a
SVGDocument
in TypeScript?The text was updated successfully, but these errors were encountered: