TypeScript Concepts

Distributive conditional types — per-union-member computation

When the checked side of a conditional is a naked type parameter, a union argument distributes across its constituents. Wrapping the checked parameter and comparison type in tuples suppresses that behavior. The empty union never produces never for a distributing conditional. Distribution changes resulting types, not runtime arrays. Observed output: '4'. Local example verified with TypeScript 5.8.3, strict checking, ES2022/CommonJS and Node.js 22.16.0; declarations enabled.

Formal Syntax & Structure

typescript syntaxtypescript
type Wrap<T> = T extends unknown ? T[] : never;

Working Example

Example Snippettypescript
type Wrap<T> = T extends unknown ? T[] : never;const words: Wrap<string | number> = ["cat", "dog"];const nums: Wrap<string | number> = [1, 2];console.log(words.length + nums.length);
TypeScript Reference