Skip to content

Control Flow Type Inference: Inferred Type Varying by Condition Order #11426

Description

TypeScript Version: nightly (2.1.0-dev.20161006)

Code

typeA_or_C_Child=A|C_Child;interfaceA{a: string;}interfaceB{b: string;}interfaceC{c: string;}interfaceC_ChildextendsA,C{extra: string;}declarefunctionisA(it: any): it is A;declarefunctionisB(it: any): it is B;declarefunctionisC(it: any): it is C;declarefunctionisA_or_C_Child(it: any): it is A_or_C_Child;letitem: any;if(isA_or_C_Child(item)&&!isC(item)&&isB(item)){item;// inferred as A & B}if(isA_or_C_Child(item)&&isB(item)&&!isC(item)){item;// inferred as A_or_C_Child & B}

Expected behavior:
Within the the last two if statements, item should be inferred to be the same type, as both if statements use the same type guards &&ed together.

Actual behavior:
item is (correctly, I think) inferred as A & B in the first if, but as A_or_C_Child & B in the second.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions