Closed
Description
TypeScript Version: 3.0.0-dev.201xxxxx
I was unable to try this. This is attempted on current playground version (2.8 or 2.9, the playground does not specify)
Search Terms: NonNullable, union
Code
declare function test<T>(condition: T): NonNullable<T>;
enum A {
ONE,
TWO,
}
function thing(x: A.ONE) { // or a union type of some of the enum values.
if (x === A.TWO) {
// x cannot be A.TWO
}
const y = test(x);
if (y === A.TWO) {
// y can be A.TWO....
}
}
Expected behavior:
y should not be assignable to A.TWO. y should remain A.ONE type.
Actual behavior:
y becomes type A instead of incoming A.ONE type.
Thanks for taking a look!