microsoft / microsoft/TypeScript
NodeList should be generic instead of having NodeListOf
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
lib Update Request
I may be missing something, but I don't see why NodeListOf exists instead of just having NodeList itself be generic. Maybe it's a vestige from a time before generic parameter defaults.
NodeList should be able to be generic with a default value of Node.
Configuration Check
afaik, this is true of all versions of lib.dom.ts. I've checked up to 5.0
Missing / Incorrect Definition
I think this should be a backwards compatible change:
interface NodeList<TNode extends Node = Node> {
readonly length: number;
item(index: number): TNode | null;
forEach(callbackfn: (value: TNode, key: number, parent: NodeList<TNode>) => void, thisArg?: any): void;
[index: number]: TNode;
}
/** @deprecated Use NodeList */
interface NodeListOf<TNode extends Node> extends NodeList<TNode> {
item(index: number): TNode;
}
Sample Code
let getDivs = (): NodeList<HTMLDivElement> => {/* ... */};
Documentation Link
N/A though removing NodeListOf would remove a type that's only present in lid.dom.d.ts, not the actual DOM APIs.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib.dom.ts and locate the NodeList and NodeListOf declarations. Compare them with the requested generic default and deprecated compatibility alias; the work is done when NodeList supports the shown HTMLDivElement usage while existing NodeListOf code remains compatible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100