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

NodeListOf#item misses return type "null"

Open danielrentz opened this issue 4 years ago • 1 comments

Interface NodeList is correctly typed

interface NodeList {
    item(index: number): Node | null;
}

but interface NodeListOf is missing the null type:

interface NodeListOf<TNode extends Node> extends NodeList {
    item(index: number): TNode;
}

therefore TSC does not warn about missing null checks:

const node = document.childNodes.item(999999).firstChild;

danielrentz avatar Feb 08 '22 09:02 danielrentz

~~Agree 👍🏻 open to changes here~~

Changed my mind after thinking about it in https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1268, this is probably too big of an ecosystem break

orta avatar Feb 16 '22 14:02 orta