0Pricing
TypeScript Academy · Lesson

Template Literal Types: String Patterns

Combine string unions into pattern types.

Welcome

Template literal types use backtick syntax at the type level to construct string types from combinations of other string types.

Basic Template Literal Type

Combine string literal types with template syntax.
type Greeting = `Hello, ${string}`;
const g: Greeting = 'Hello, World'; // OK
// const bad: Greeting = 'Hi there'; // Error

All lessons in this course

  1. Mapped Types: Transforming Object Types
  2. Modifiers in Mapped Types: readonly and ?
  3. Template Literal Types: String Patterns
  4. Key Remapping with as in Mapped Types
← Back to TypeScript Academy