TypeScript Version: 2.0.3 AND nightly (2.1.0-dev.20161102)
Code
interfaceFoo{kind: 'foo';a: number;}interfaceBar{kind: 'bar';b: string;}functiontest(x: Bar|Foo){if(x.kind==='foo'){console.log(x.a);// Valid, as expected}}interfaceQux{c: boolean;}functiontest2(x: (Bar|Foo)&Qux){if(x.kind==='foo'){// Type of x should be Foo&Qux now, but is still (Bar|Foo)&Quxconsole.log(x.a);// Error}}Expected behavior:
In test2(), the discriminated union check should narrow the type down to (Foo)&Qux, letting you access property a, since a is guaranteed to be there if x.type === 'foo'.
Actual behavior:
No type narrowing is done whatsoever. The type of x remains (Foo|Bar)&Qux.
TypeScript Version: 2.0.3 AND nightly (2.1.0-dev.20161102)
Code
Expected behavior:
In
test2(), the discriminated union check should narrow the type down to(Foo)&Qux, letting you access propertya, sinceais guaranteed to be there ifx.type === 'foo'.Actual behavior:
No type narrowing is done whatsoever. The type of x remains
(Foo|Bar)&Qux.