Template literal types combine literal strings with unions to generate a set of possible string types, similar to JS template literals but evaluated by the compiler.
ts
type Chain = "eth" | "polygon" | "arb";
type Env = "main" | "test";
type Endpoint = `${Chain}-${Env}.rpc.example.com`;
// "eth-main.rpc.example.com" | "eth-test.rpc.example.com" | "polygon-main.rpc.example.com" | ... (6 combinations)
type EventName<T extends string> = `on${Capitalize<T>}`;
type ClickEvent = EventName<"click">; // "onClick"Combining a literal union with a template produces the cross-product of all combinations — here 3 chains × 2 environments = 6 possible endpoint strings, each individually valid at the type level. Intrinsic string manipulation types (`Uppercase`, `Lowercase`, `Capitalize`, `Uncapitalize`) are often used alongside template literals to transform casing.