TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

XMLDocument createElement should return an Element

Open gwartnes opened this issue 1 year ago • 0 comments

When creating an XMLDocument instance, and then using that XMLDocument to create an Element, the type that is assigned is HTMLElement. It should be an Element.

Simple repro:

My compilation target is esnext and my lib is the default.

const xmlDoc = document.implementation.createDocument(null, 'root'); // the type of `xmlDoc` here is `XMLDocument`
const personElement = xmlDoc.createElement('person'); // the type of `personElement` here is `HTMLElement`
personElement.focus(); // Error: personElement.focus is not a function

Some relevant documentation: https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement#return_value (Emphasis added)

Note: A new HTMLElement is returned if the document is an HTMLDocument, which is the most common case. Otherwise a new Element is returned.

gwartnes avatar Jul 13 '23 19:07 gwartnes