Template literal type

Builds string literal types by interpolating other types into a template.

Since TS 4.1 Spec ↗

Syntax

`prefix${T}suffix`

Examples

type Lang = 'en' | 'fr';
type Locale = `${Lang}-US`; // 'en-US' | 'fr-US'
type EventName<T extends string> = `on${Capitalize<T>}`;
type Click = EventName<'click'>; // 'onClick'

Notes

Template literal types interpolate unions, distributing across every combination to produce a union of string literals. They pair well with the intrinsic `Uppercase`, `Lowercase`, `Capitalize`, and `Uncapitalize` types and enable typed key remapping in mapped types.

See also