Skip to content

Add a generic createElementNS overload for the XHTML namespace - #2582

Merged
github-actions[bot] merged 1 commit into
microsoft:mainfrom
MartinFerret:fix/createelementns-xhtml-tagname
Nov 6, 2026
Merged

github-actions[bot] merged 1 commit into
microsoft:mainfrom
MartinFerret:fix/createelementns-xhtml-tagname

Conversation

@MartinFerret

@MartinFerret Martin Ferret (MartinFerret) commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes microsoft/TypeScript#63556

document.createElementNS("http://www.w3.org/1999/xhtml", "div") currently returns HTMLElement, while the SVG and MathML namespaces already have a generic overload that maps the tag name to the right element type.

This adds the matching overload for the XHTML namespace, placed before the existing string overload (same pattern as SVG and MathML):

createElementNS<K extends keyof HTMLElementTagNameMap>(namespaceURI: "http://www.w3.org/1999/xhtml", qualifiedName: K): HTMLElementTagNameMap[K];
  • Known tag names now return the specific type ("div" -> HTMLDivElement).
  • Unknown tag names and string values still return HTMLElement.
  • A unit test is added in unittests/files/createelementns.ts.

Note: like createElement, a variable declared with let el = document.createElementNS(xhtml, "div") is now typed HTMLDivElement, so assigning a different element type to it later becomes an error.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR!

This section of the codebase is owned by Kagami Sascha Rosylight (@saschanaz) - if they write a comment saying "LGTM" then it will be merged.

@saschanaz

Copy link
Copy Markdown
Contributor

Looks good, thanks! LGTM

@github-actions
github-actions Bot merged commit 51e2d51 into microsoft:main Nov 6, 2026
7 checks passed
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Merging because Kagami Sascha Rosylight (@saschanaz) is a code-owner of all the changes - thanks!

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

Successfully merging this pull request may close these issues.

Overload missing from createElementNS

2 participants