TypeScript Concepts
Type instantiation limits — bounded compiler work
The compiler limits some type computations to prevent excessive checking work. A recursive conditional can hit TS2589 even if a mathematical result exists. Limits and heuristics vary by compiler and expression; avoid treating one tested depth as a universal limit. Prefer simpler contracts or bounded computation for public APIs. Observed output: '3'. 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 Build<N extends number, A extends unknown[] = []> = A["length"] extends N ? A : Build<N, [...A, unknown]>;Working Example
Example Snippettypescript
type Build<N extends number, A extends unknown[] = []> = A["length"] extends N ? A : Build<N, [...A, unknown]>;const items: Build<3> = [1, 2, 3];console.log(items.length);