Description
π Search Terms
getElementById
π Version & Regression Information
TypeScript 5.7.2
β― Playground Link
π» Code
No response
π Actual behavior
The getElementById
interface looks wrongly typed, as TypeScript ensures it would return a HTMLElement
(see for example https://www.typescriptlang.org/docs/handbook/dom-manipulation.html#documentgetelementbyid)
However, MDN and the specification claims this method would return a generic Element
, in particular it could return a SVGElement
or any other kind of element (see: https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById). A quick trial in a browser obviously confirms such case is legit.
π Expected behavior
The return type of getElementById
should be Element | null
EDIT Apparently the issue is known since at leats 2020. Fair enough. Is it possible to have a documentation that mentions this limitation and others? It would help others so much.
Additional information about the issue
No response