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
- Typing Translation Keys
- Interpolation Type Safety
- Pluralization with Types
- Locale-Aware Type Inference