Closed
Description
TypeScript Version: 2.7.0-dev.201xxxxx
Search Terms:
discriminated union, narrowing, intersection
Code
type DU = { t: '1', a: 2 } | { t: '2', c: 3 }
type C1 = DU & { t: '1' }
declare const foo: C1
foo.a // <= does not compile
Expected behavior:
C1 should be inferred to { t: '1', a: 2 }
, so it should be clear that a can be accessed
Actual behavior:
C1 is inferred to ({ t: "1"; a: 2; } & { t: "1"; }) | ({ t: "2"; c: 3; } & { t: "1"; })
Note the impossible type ({ t: "2"; c: 3; } & { t: "1"; })
is not removed!
Playground Link:
link
Related Issues: