Closed
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.