Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeList should be generic instead of having NodeListOf #53540

Open
justinfagnani opened this issue Mar 27, 2023 · 1 comment
Open

NodeList should be generic instead of having NodeListOf #53540

justinfagnani opened this issue Mar 27, 2023 · 1 comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@justinfagnani
Copy link

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.

@jakebailey
Copy link
Member

FYI you probably want to report this at the repo which generates lib.dom.d.ts: https://github.com/microsoft/TypeScript-DOM-lib-generator

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants