Skip to content

Node.childNodes return type appears to be slightly inaccurateΒ #18194

Closed
@dsifford

Description

@dsifford

Greetings!

Ran into this earlier today and I'm wondering if it's a bug or if I'm just mistaken for what I assumed would be returned.

Below is a snapshot of the definition of Node.

https://github.com/Microsoft/TypeScript/blob/c7b4ed3a91964915b953b34ad2ae72f36e7d6efe/lib/lib.dom.d.ts#L8260-L8265

Currently, Node.childNodes returns a NodeList which is mostly correct. However, wouldn't it be more accurate to instead return a NodeListOf<Node & ChildNode> so that the remove method is exposed?

Example of the issue:

declare const node: Node;

for (const child of node.childNodes) {
    child.remove(); // fails "Property 'remove' does not exist on type 'Node'
}

Happy to submit a PR for this if needed (I'm going to also submit one for the issue I opened yesterday when I get some spare time this weekend).

Thanks in advance πŸ˜„

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions