microsoft / microsoft/TypeScript
The type of Document.documentElement could be SVGSVGElement
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Currently, the type of Document.documentElement is HTMLElement:
But it is possible for a Document’s documentElement property to be of type SVGSVGElement which is not a subtype of HTMLElement:
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.
Also, why isn’t there a SVGDocument in TypeScript?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at lib/lib.dom.d.ts, the linked declaration for Document.documentElement, and reproduce the DOMParser SVG example. Done means the DOM typings accurately admit the demonstrated SVG documentElement and the issue’s SVGDocument question is resolved, with the relevant declaration checks passing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100