Skip to content

Strange inference failure #20596

Closed
Closed
@jods4

Description

@jods4

TypeScript Version: 2.6.2

Code

let x: { nodes: DocumentFragment, _start: Comment };
let iter: Node | null, nodes: DocumentFragment;
({ nodes, _start: iter } = x!);
while (iter) {
    let next = iter.nextSibling;
    nodes.appendChild(iter);
    iter = next;
}

Expected behavior: next is typed as Node | null.

Actual behavior: next is typed as any, which raises an error under noImplicitAny.

Comment: This is really strange because tooltips indicate that at this point iter is narrowed to Node and iter.nextSibling is of course Node | null.
So it makes no sense that let next = iter.nextSibling isn't type as such.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions