Tuesday, 27 April, 2021 UTC


Summary

In this lesson, we're going to explore template literal types, another powerful feature of TypeScript's type system. Template literal types have the same syntax as template literals in JavaScript, but they're used in type positions. Using template literal types, we can produce a union of string literal types and perform string concatenation in the type space: ```ts type Dimension = "block" | "inline"; type MarginProperty = `margin-${Dimension}`; ``` ## Additional Reading - [Template Literal Types](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html) - [String Literal Types in TypeScript](https://mariusschulz.com/blog/string-literal-types-in-typescript) - [Mapped Types in TypeScript](https://mariusschulz.com/blog/mapped-types-in-typescript) - [`keyof` and Lookup Types in TypeScript](https://mariusschulz.com/blog/keyof-and-lookup-types-in-typescript)