Template Literal Types

Jan-17, 2025 · 1min

change language

Learn how to use template literal types in TypeScript, create dynamic type definitions through string templates, and improve type safety and code readability

Template Literal Types

Template Literal Types is a type in TypeScript, it allows you to create a string type that can contain variables.

type  = 'world'
type Greeting = `hello ${}`
type Greeting = "hello world"
type  = 'welcome_email' | 'email_heading'
type  = 'footer_title' | 'footer_sendoff'

type AllLocaleIDs = `${ | }_id`
type AllLocaleIDs = "welcome_email_id" | "email_heading_id" | "footer_title_id" | "footer_sendoff_id"