Why does TypeScript distribute conditional types over union types only when the checked type is a naked type parameter?

2 days ago 2
ARTICLE AD BOX

I’m trying to understand how conditional types behave differently when a type parameter is “naked.” For example:

type Wrapped<T> = [T] extends [string] ? "is string" : "not string"; type Naked<T> = T extends string ? "is string" : "not string"; type Test1 = Wrapped<string | number>; // 'not string' type Test2 = Naked<string | number>; // 'is string' | 'not string'

I understand what happens (distribution or not), but I don’t fully get why TypeScript treats these differently internally.
What’s the type system or compiler logic behind this distinction, and how does it impact generic library design or runtime type inference patterns?

Read Entire Article