TypeScript · Middle · Question 15 of 75

What are template literal types?

type Event = 'click' | 'focus';
type Handler = `on${Capitalize<Event>}`;

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.

Further reading

Problem with a question

TypeScript · Middle · question 15

Test yourself

Take the TypeScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz