TypeScript · Senior · Question 24 of 75
Why can the template type ` ${A}-${B}-${C} ` over three large unions cause an error?
- ✓Correct answer: The resulting union is too large, and the compiler has a limit
- 2Template types don't support more than two substitutions
- 3Union types can't be substituted into template literals at all
Explanation
A template with unions distributes over every combination: 100 × 100 × 100 = 1,000,000 members. TypeScript limits union size (around 100,000) and reports "Expression produces a union type that is too complex". The fix is a more general type (` ${string}-${string} `) or validation via a function.