-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add type safety for i18next's T Function #9820
Comments
can i work on this issue @rithviknishad |
Do comment how you are planning to solve this before taking it up. |
Hi @rithviknishad , Do I understand the issue correctly? Currently, the t("fitlers"); // Runtime error, no TypeScript warning. We aim to make the I will write a script that extracts all valid keys from the translation JSON files (e.g., ex. from en.json Generate: export type TranslationKeys =
| "404_message"
| "APPETITE__CANNOT_BE_ASSESSED"
| "APPETITE__INCREASED" Next
t("filters"); // ✅ Valid
t("fitlers"); // ❌ TypeScript Error I'd like to work on the issue if the approach seems right or I may correct my approach |
Can i take this up?
|
Steps to add type safety for i18next's T Function:-
Can I work on the issue if my approach seems right? |
Hi @rithviknishad , Here’s my proposed approach to address the issue: Objective Steps Write a script to parse all JSON files in public/locales, flatten nested keys, and generate a translationKeys.d.ts file containing a TranslationKeys type. Create a declaration file (src/i18n/i18next.d.ts) to extend i18next with TranslationKeys. Add a script (generate-keys) to automate the creation of translationKeys.d.ts whenever translation files are updated. Use the generated TranslationKeys in i18next to enforce type safety. |
Refer: https://www.i18next.com/overview/typescript
The text was updated successfully, but these errors were encountered: