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 16:09:55 +01:00
committed by GitHub
parent 03b730db58
commit 7766ae92d7
6 changed files with 621 additions and 574 deletions
File diff suppressed because it is too large Load Diff
+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
+9 -1
View File
@@ -8,7 +8,15 @@ Please see LICENSE files in the repository root for full details.
export { ModuleLoader, ModuleIncompatibleError } from "./loader";
export type { Api, Module, ModuleFactory } from "./api";
export type { Config, ConfigApi } from "./api/config";
export type { I18nApi, Variables, Translations, SubstitutionValue, Tags } from "./api/i18n";
export type {
I18nApi,
Variables,
StringVariables,
RichVariables,
Translations,
SubstitutionValue,
Tags,
} from "./api/i18n";
export type * from "./models/event";
export type * from "./models/Room";
export type * from "./api/composer";