-
Notifications
You must be signed in to change notification settings - Fork 291
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
feat(i18n): enhance types #18347
feat(i18n): enhance types #18347
Conversation
@@ -0,0 +1,32 @@ | |||
const fs = require('fs'); |
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.
an important file
@@ -108,25 +108,58 @@ const MessageDetails = ({failure, isMessageFocused, allUsers}: MessageDetailsPro | |||
</> | |||
); | |||
|
|||
const getText = () => { |
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.
a lot of changes there, but it had to be done, because of the type, logic remains the same as it was
@@ -19,11 +19,28 @@ | |||
|
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.
an important file
identifier: Id, | ||
...args: ExtractSubstitutionKeys<TranslationStrings[Id]> extends never | ||
? [substitutions?: undefined, dangerousSubstitutions?: Record<string, string>, skipEscape?: boolean] | ||
: [substitutions: Substitutions<Id>, dangerousSubstitutions?: Record<string, string>, skipEscape?: boolean] |
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.
unfortunately, the args
are mandatory here (instead of typing each parameter separately), because we have to mark substitutions
either optional (the ?
sign) with undefined type, or required with the Substitutions<Id>
type
@@ -0,0 +1,1654 @@ | |||
declare module 'I18n/en-US.json' { |
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.
an important file
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.
i've thought about creating a normal .ts
file, but IMO .d.ts
is fine in this case
the normal .ts
file would require additional import + type assertion the json
@@ -25,6 +25,35 @@ const commonConfig = require('./webpack.config.common'); | |||
|
|||
const srcScript = 'src/script/'; | |||
|
|||
const updateTranslationTypesPlugin = { |
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.
an important file
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #18347 +/- ##
==========================================
- Coverage 46.56% 46.55% -0.02%
==========================================
Files 834 834
Lines 26016 26029 +13
Branches 5905 5905
==========================================
+ Hits 12114 12117 +3
- Misses 12387 12395 +8
- Partials 1515 1517 +2 |
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.
LGTM!
|
Description
Automatically generates types for internalization file (
en-US.json
). The script runs on the server start and on a file change (webpack / hot reload). Every change to theen-US.json
will cause an update ofi18n.d.ts
.The
t
function now checks for dynamic value types. There's also a unified syntax for passing variables, we eliminate multiple ways (with an object and without) of passing dynamic values. Works with single and multiple values.What it means?
Before:
After:
I've fixed many places to use the new way. I've left some places with
@ts-expect-error
- I don't want to break anything / it should be done in other PRs.Checklist