You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeT=number|stringletx: T|null// Inspect the type of x
Expected behavior:
Since in most cases, TypeScript takes care to preserve type names, I'd hope x to get type T | null.
Actual behavior:
Union types that are part of another union type are eagerly flattened into the outer type, producing a type printed as number | string | null.
I am running into this when using the TypeScript compiler as a library as part of a documentation generating system. I have some named union types in my API that become noisy and hard to interpret for users when they are expanded every time they appear in some union type.
TypeScript Version: 4.1.3
Search Terms: nested union, flatten union
Code
Expected behavior:
Since in most cases, TypeScript takes care to preserve type names, I'd hope
x
to get typeT | null
.Actual behavior:
Union types that are part of another union type are eagerly flattened into the outer type, producing a type printed as
number | string | null
.I am running into this when using the TypeScript compiler as a library as part of a documentation generating system. I have some named union types in my API that become noisy and hard to interpret for users when they are expanded every time they appear in some union type.
Playground Link: here
Related Issues: No.
The text was updated successfully, but these errors were encountered: