Node.childNodes return type appears to be slightly inaccurate #18194
Copy link
Copy link
Closed
Labels
Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueHelp WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
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.
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 😄
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueHelp WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript
Activity
mhegazy commentedon Aug 31, 2017
Kitson Kelly (@kitsonk) thoughts?
kitsonk commentedon Sep 1, 2017
The living standard says that:
and that a
childis:But of course there is a challenge in modelling that in Web IDL, because the types in there don't have the concept of generics, so both the IDL from Edge and the WHATWG IDL don't say anything but
NodeList. So it seems totally appropriate for it to beNodeListOf<Node & ChildNode>as that is clearly more spec aligned.