Template Literal Types
Combine string literal types with template literal syntax to derive types like event names, CSS property strings, and API route paths.
What Are Template Literal Types?
TypeScript can build string types from template literals at the type level. Combined with union types, you can express thousands of valid strings without listing each one.
Basic Template Literal Type
Use backtick-quoted strings in type position — they accept other types as interpolations.
type Greeting = `Hello, ${string}!`;
const a: Greeting = 'Hello, Alice!'; // OK
const b: Greeting = 'Hi, Alice!'; // Error