-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
chore(i18n): improve type safety #7781
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances type safety for internationalization by introducing and applying a new IntlMessageKeys
type across the codebase, ensuring that translation functions only accept valid keys.
- Updated JSDoc in the i18n package to return a strongly typed
Locale
- Added and imported
IntlMessageKeys
, then asserted various label and info strings as valid keys - Introduced the
IntlMessageKeys
generic type and integrated it into types, hooks, components, and tests
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
packages/i18n/lib/index.mjs | Updated JSDoc @returns to use Locale from types |
apps/site/util/downloadUtils/index.tsx | Cast various label fields to IntlMessageKeys for safety |
apps/site/types/navigation.ts | Imported IntlMessageKeys for FooterConfig.text |
apps/site/types/i18n.ts | Defined the IntlMessageKeys generic based on Locale |
apps/site/types/blog.ts | Applied IntlMessageKeys to BlogCategory |
apps/site/tests/e2e/general-behavior.spec.ts | Refined verifyTranslation signature to accept Locale type |
apps/site/hooks/react-generic/useSiteNavigation.ts | Imported IntlMessageKeys for navigation hook |
apps/site/components/Downloads/Release/ReleaseCodeBox.tsx | Cast info key to IntlMessageKeys and imported the type |
Comments suppressed due to low confidence (2)
apps/site/components/Downloads/Release/ReleaseCodeBox.tsx:18
- The import path includes a '.js' extension, but the type is defined in '#site/types/i18n.ts'. Update the import to
'#site/types/i18n'
to ensure correct module resolution.
import type { IntlMessageKeys } from '#site/types/i18n.js';
apps/site/hooks/react-generic/useSiteNavigation.ts:8
- [nitpick] The
IntlMessageKeys
import is not used in this file. Remove the unused import to keep dependencies clean and avoid lint warnings.
IntlMessageKeys,
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## main #7781 +/- ##
==========================================
+ Coverage 75.31% 75.33% +0.01%
==========================================
Files 96 96
Lines 7856 7862 +6
Branches 192 192
==========================================
+ Hits 5917 5923 +6
Misses 1938 1938
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
aviv could you apply thing such as proposed here it's look little be simpler |
That's what I did, see the |
But I didn't get why you need a |
We cast in the download utilities because they are from JSON, so the JSON strings must be casted to our type. |
Lighthouse Results
|
Description
This PR updates our types to better reflect i18n. For example,
t("...")
will now only accept valid i18n keys.Validation
Related Issues
Check List
pnpm format
to ensure the code follows the style guide.pnpm test
to check if all tests are passing.pnpm build
to check if the website builds without errors.