You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
There is no plan to announce a clean-up of the API in the forthcoming 3 years (say -- since the link you mention is already 3 years old) and just give users time to migrate their code base ?
Is it maybe possible to mention that limitation in the doc or something, so that other people dont have to dig github issues (which is not really direct to dig in this issue: I couldnt find any of the links mentioned above) ?
π Search Terms
getElementById
π Version & Regression Information
TypeScript 5.7.2
β― Playground Link
https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABAUwBQA8BciDOUBOMYA5gJTYASAKgLIAyAogDbIC2yYUiAPomCEyaIA3onzIoIfEgAmcCCHacAdMQnM2HKACEAngEkZGUgG5EAXyA
π» Code
No response
π Actual behavior
The
getElementById
interface looks wrongly typed, as TypeScript ensures it would return aHTMLElement
(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 aSVGElement
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 beElement | 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
The text was updated successfully, but these errors were encountered: