microsoft / TypeScript-DOM-lib-generator

Tool for generating dom related TypeScript and JavaScript library files
Apache License 2.0
622 stars 421 forks source link

NodeListOf#item misses return type "null" #1261

Open danielrentz opened 2 years ago

danielrentz commented 2 years ago

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;
orta commented 2 years ago

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