TypeScript · Senior · Question 24 of 75

Why can the template type ` ${A}-${B}-${C} ` over three large unions cause an error?

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.

Further reading

Problem with a question

TypeScript · Senior · question 24

Test yourself

Take the TypeScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz