TypeScript Version: 2.5.1-insiders.20170825
Code
interfaceA{identity: 'a';a: number;}interfaceB{identity: 'b';b: number;}interfaceC{}// This function errors as written. It does not error if changed to `value: C & (A | B)`.functionf(value: ((A|B)&C)&(A|B)): number{switch(value.identity){case'a':
returnvalue.a;// Error: Property 'a' does not exist on 'B & C'.case'b':
returnvalue.b;// Error: Property 'b' does not exist on 'A & C'.}}Expected behavior:
No error. This is a discriminated union and the switch statement should infer property a.
Furthermore, I expect that the following types are equivalent:
((A | B) & C) & (A | B)(A | B) & C & (A | B)C & (A | B)
However, 1 behaves differently from 2 and 3.
Actual behavior:
TS errors because it fails to infer that the type cannot be B & C in the first case.
TypeScript Version: 2.5.1-insiders.20170825
Code
Expected behavior:
No error. This is a discriminated union and the switch statement should infer property
a.Furthermore, I expect that the following types are equivalent:
((A | B) & C) & (A | B)(A | B) & C & (A | B)C & (A | B)However, 1 behaves differently from 2 and 3.
Actual behavior:
TS errors because it fails to infer that the type cannot be
B & Cin the first case.