Closed
Description
TypeScript Version: 3.8.0-dev.20191105
Search Terms: in operator, union, unsound
Code
type Union = { foo: string; foo2: string } | { bar: number; bar2: number };
const union: Union = { foo: 'a', bar: 1, bar2: 2 };
if('foo' in union) {
union; // incorrectly inferred as { foo: string, foo2: string }
}
Expected behavior: Type of union
should be narrowed to Union & { foo: any }
, or not narrowed.
Actual behavior: Type of union
is narrowed to { foo: string, foo2: string }
despite having no foo2
property.