types
Generate TypeScript types from your translation files, so a typo in a key fails at compile time and your editor completes the keys.
Generates TypeScript definitions from your translation files for full type-safety and autocompletion.
What the types give you and how to set them up in your app: Typed keys.
bash
npx i18next-cli types [options]
Options
--watch, -w: Re-run automatically when translation files change--ci: Exit with a non-zero status if the generated TypeScript definitions are out of date (check-only, writes nothing). Cannot be combined with--watch.--quiet, -q: Suppress spinner and non-essential output (for CI or scripting)
Notes
- With
extract.defaultNS: false, the generateddefaultNScomes from your resource files, because i18next's types cannot expressfalse. Adjusti18next.d.tsif your runtime config uses another default namespace. - With
extract.messageFormat: 'icu'or'mf2', a newly generatedi18next.d.tssetsparseInterpolationto the same value when your i18next is 26.5.0 or later (falsewith 26.2.0 to 26.4.x), sot()options are checked against the arguments of each message. An existingi18next.d.tsis not rewritten;typeswarns until you add the line. - With
strictInterpolationChecks(the default from i18next 27),t()needs its options for every string with{{variables}}. Declare the variablesinterpolation.defaultVariablesfills in with thedefaultVariablestype option, type the key of a wrapper aroundt()withParseKeysWithoutVariables<'ns'>, and list the same variables inlint.defaultVariables, becauselintdoes not read the.d.ts.