Fix i18n types (#33305)

Without the fix the return type would be `string` in cases where it should be `ReactNode`
This commit is contained in:
Michael Telatynski
2026-04-27 15:09:55 +00:00
committed by GitHub
parent 03b730db58
commit 7766ae92d7
6 changed files with 621 additions and 574 deletions
+18 -6
View File
@@ -33,13 +33,25 @@ export type SubstitutionValue = number | string | ReactNode | ((sub: string) =>
* Variables to interpolate into a translation.
* @public
*/
export type Variables = {
/**
* The number of items to count for pluralised translations
*/
export type Variables = StringVariables | RichVariables;
/**
* Variables that are guaranteed to only contain primitive (string-safe) values
* @public
*/
export interface StringVariables {
count?: number;
[key: string]: number | string | null | undefined;
}
/**
* Variables that may contain ReactNodes or functions, requiring a ReactNode return
* @public
*/
export interface RichVariables {
count?: number;
[key: string]: SubstitutionValue;
};
}
/**
* Tags to interpolate into a translation, where the value is a ReactNode or a function that returns a ReactNode.
@@ -68,7 +80,7 @@ export interface I18nApi {
* @param key - The key to translate
* @param variables - Optional variables to interpolate into the translation
*/
translate(this: void, key: keyof Translations, variables?: Variables): string;
translate(this: void, key: keyof Translations, variables?: StringVariables): string;
/**
* Perform a translation, with optional variables
* @param key - The key to translate