Skip to content

The type of Document.documentElement could be SVGSVGElement #29052

Open
@EFanZh

Description

@EFanZh

Currently, the type of Document.documentElement is 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:

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    RevisitAn issue worth coming back toSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions