TypeScript · Middle · Question 15 of 75
What are template literal types?
type Event = 'click' | 'focus';
type Handler = `on${Capitalize<Event>}`;- ✓Correct answer: String types built from a template: here
'onClick' | 'onFocus' - 2Templates for generating code at compile time
- 3A string type checked against a regular expression
Explanation
Template literals work at the type level and distribute over unions. There are built-in transformations: Uppercase, Lowercase, Capitalize, Uncapitalize. They're used to type event keys, CSS variables and routes.