TypeScript 4.3 turns the type system into a programming language itself.
Template Literal Types
You can now concatenate types!
type Color = "red" | "blue";
type Quantity = "one" | "two";
type Item = `${Color}-${Quantity}`;
// Item is "red-one" | "red-two" | "blue-one" | "blue-two"
This is incredibly useful for typing strings that follow a specific pattern, like CSS classes or Event names.
Discover more from C4: Container, Code, Cloud & Context
Subscribe to get the latest posts sent to your email.