-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this
Milestone
Description
TypeScript Version: 3.1.6
Search Terms: ChildNode Node nextSibling
Code
// a basic loop over elements in the DOM
let element = document.body.firstChild; // is a ChildNode | null
while (element) {
// ... do something with element
let sibling = element.nextSibling; // is a Node | null -- why?
element = sibling; // uh-uh!
}
Expected behavior:
Surely a sibling of a child is itself also a child (of the same parent). So siblings should be assignable using the same variable.
Actual behavior:
Error:
Type 'Node | null' is not assignable to type 'ChildNode | null'.
Type 'Node' is not assignable to type 'ChildNode'.
Property 'after' is missing in type 'Node'. [2322]
Related Issues:
I think this is what #27453 also refers to, but fails to describe accurately so it has been closed.
In any case this is related to the 'solution' in #24633 which clearly shows the type of nextSibling as Node, not ChildNode.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this