Type inference not correctly inferring type of generic

17 hours ago 1
ARTICLE AD BOX

I have the following code:

enum UnionType { a, b } type A = { type: UnionType.a }; type B = { type: UnionType.b }; type AB = A | B; function f<T extends AB>(x: T, y: T) { if(x.type == UnionType.a) { // in here, it correctly infers that x is of type A // but it does not infer that y is also of type A } }

Should this work the way I think it does? I would prefer not to have to put x, y into an object and do type inference on the object if at all possible.

Read Entire Article