Template literal types (TypeScript 4.1+) construct string types from other strings and types. Same `${}` syntax as runtime template literals but at the type level. When an interpolated union is used, the result is a union of all combinations. Combined with mapped types and the as clause, they generate entire typed API surfaces. Intrinsic string manipulation types (Uppercase, Lowercase, Capitalize, Uncapitalize) transform string literal type casing.
Each stage in order — click any step to read what it does.
How unions expand in template literal types.
The trade-offs worth knowing before you build this.
A single mapped type with template literal keys can generate a complete typed event handler interface, getter/setter API, or CSS property set from a small union of strings.
Template literal types with infer can parse URL patterns like '/users/:id' at the type level, extracting parameter names as string literal unions — enabling fully typed routing.
Template literal types alone are just string construction. Combined with [K in keyof T as \`get${Capitalize<K>}\`], they transform entire object APIs at compile time with zero boilerplate.
Sign in to share your feedback and join the discussion.