TypeScript Compiler Diagnostics
TS2590: Union too complex to represent
Template literal interpolation can form a Cartesian product of unions. Five positions of ten alternatives require up to 100,000 distinct strings in this fixture, exceeding the pinned compiler representation guard. Use a broader type and a runtime validator when exact enumeration is impractical; this intentionally trades static precision for runtime validation. Baseline: TypeScript 5.8.3 with the shown configuration. Diagnose the reported location and nested message before applying a fix; other causes may require a different correction. The first project is intentionally invalid; create the corrected project separately. Neither example requires disabling strict checking.
Formal Syntax & Structure
typescript syntaxtypescript
TS2590 (compiler diagnostic code, not TypeScript syntax)Working Example
Example Snippettypescript
// INTENTIONALLY INVALID — reproduce// File: tsconfig.json (omit this label){ "compilerOptions": { "strict": true, "target": "ES2022", "module": "CommonJS", "types": [], "lib": [ "ES2022", "DOM" ], "noEmitOnError": true, "outDir": "dist" }, "files": [ "main.ts" ]}
// File: main.ts (omit this label)type Digit = "0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9";type Postal = `${Digit}${Digit}${Digit}${Digit}${Digit}`;
// Run: tsc -p . --pretty false// Expected: TS2590; no emitted main file.
// CORRECTED PROJECT// File: tsconfig.json (omit this label){ "compilerOptions": { "strict": true, "target": "ES2022", "module": "CommonJS", "types": [], "lib": [ "ES2022", "DOM" ], "noEmitOnError": true, "outDir": "dist" }, "files": [ "main.ts" ]}
// File: main.ts (omit this label)type Postal = string;function postal(value: string): Postal { if (!/^\d{5}$/.test(value)) throw new Error("Invalid code"); return value; }console.log(postal("01234"));
// Run: tsc -p . --pretty false// Expected: no diagnostics.// Run: node dist/main.js// Expected stdout: 01234