-
-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Disallow passing
null
, undefined
or boolean
as an ICU ar…
…gument (#1561) These are errors now: ```tsx t('message', {value: null}); t('message', {value: undefined}); t('message', {value: false}); ``` If you really want to put a raw boolean value in a message, you can cast it to a string first: ```tsx const value = true; t('message', {value: String(value)}); ```
- Loading branch information
Showing
11 changed files
with
120 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,25 @@ | ||
import type {ReactNode} from 'react'; | ||
|
||
export type ICUArg = string | number | boolean | Date; | ||
// ^ Keep this in sync with `ICUArgument` in `createTranslator.tsx` | ||
|
||
export type TranslationValues = Record<string, ICUArg>; | ||
export type TranslationValues = Record< | ||
string, | ||
// All params that are allowed for basic params as well as operators like | ||
// `plural`, `select`, `number` and `date`. Note that `Date` is not supported | ||
// for plain params, but this requires type information from the ICU parser. | ||
string | number | Date | ||
>; | ||
|
||
export type RichTagsFunction = (chunks: ReactNode) => ReactNode; | ||
export type MarkupTagsFunction = (chunks: string) => string; | ||
|
||
// We could consider renaming this to `ReactRichTranslationValues` and defining | ||
// it in the `react` namespace if the core becomes useful to other frameworks. | ||
// It would be a breaking change though, so let's wait for now. | ||
export type RichTranslationValues = Record<string, ICUArg | RichTagsFunction>; | ||
export type RichTranslationValues = Record< | ||
string, | ||
TranslationValues[string] | RichTagsFunction | ||
>; | ||
|
||
export type MarkupTranslationValues = Record< | ||
string, | ||
ICUArg | MarkupTagsFunction | ||
TranslationValues[string] | MarkupTagsFunction | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters