0Pricing
TypeScript Academy · Lesson

Typing Translation Keys

Derive a union of valid keys from message files.

Deriving Valid Translation Keys

In a type-safe i18n setup, the set of valid translation keys is derived from your messages object. A typo like t("greetng") becomes a compile error, not a missing-string bug at runtime.

A Messages Object

Start with a plain object of messages. It is the single source of truth for both values and the key type.

const messages = {
  greeting: "Hello",
  farewell: "Goodbye",
  cart: {
    empty: "Your cart is empty",
    checkout: "Proceed to checkout",
  },
} as const;

All lessons in this course

  1. Typing Translation Keys
  2. Interpolation Type Safety
  3. Pluralization with Types
  4. Locale-Aware Type Inference
← Back to TypeScript Academy