Strings are the most common source of runtime bugs in TypeScript code. You pass "400px" where the function expects "4rem". You type "onclick" instead of "onClick". You construct a URL like /api//users because you forgot to strip a trailing slash.
Most developers solve this with runtime validation or just hope for the best. But TypeScript has a feature that lets you enforce string patterns at compile time: template literal types.
I'm not talking about basic string literal unions (type Direction = "up" | "down"). Template literal types work at a different level — they let you compose and constrain strings dynamically while keeping full type safety.
Here's what they look like in practice.
The Problem Template Literal Types Solve






