Giant Unions
What
A “Giant Union” is an union type that has exploded in size, usually as a result of combining multiple large unions within a template literal type.
How
This typically happens when you interpolate several union types together, creating hundreds of thousands of possible combinations:
type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
// This creates 100,000 combinations!
type ZipCode = `${Digit}${Digit}${Digit}${Digit}${Digit}`;
Why
TypeScript has a built-in limit for union complexity. If a type becomes too large, the compiler will throw an error: Union type too complex to represent. This is because tracking an astronomical number of combinations slows down your editor’s responsiveness and increases compilation times significantly.
Summary
Avoid “type masturbation”—the act of creating hyper-specific types that don’t add practical value but do create massive complexity for the compiler.