Generic union type inferred differently from equivalent direct union type

110 views Asked by At

Consider the following:

type UnwrapNullable1 = Required<{ x?: (1 | undefined) }>["x"]
type UnwrapNullable<T> = Required<{ x?: T }>["x"]
type Test = UnwrapNullable<1 | undefined>

The type UnwrapNullable1 is correctly inferred as 1, but Test, which should be equivalent to UnwrapNullable1, is inferred as 1 | undefined.

Is this a limitation of typescript or some kind of bug?

0

There are 0 answers