Open
Description
TypeScript Version: 3.5.0-dev.20190425
The example below was taken from a real world use-case and simplified.
The U
type is distributed while the T
type remains the original union.
The T
type is wrapped with Box<T>
when U
is not an object.
type Box<T> = { value: T }
type Test<T> = [T] extends [infer U]
? U extends object
? U
: U | Box<T>
: never
type A = number | { foo: number }
type B = Test<A>
In theory, the B
type should be identical to:
type B = number | { foo: number } | Box<number | { foo: number }>
But in the latest version, the B
type is instead identical to:
type B = number | { foo: number } | Box<number | (number & { foo: number })>
This works correctly in 3.3.x but not 3.4.x and later.
Playground Link: click here