From 38e7d9b922ef8b8be4ca9c0a29bdc7186c585147 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 23 Aug 2024 15:46:33 +1000 Subject: [PATCH] fix: typings for getMessage i18n --- ts/types/Localizer.ts | 2 +- ts/util/i18n/functions/getMessage.ts | 12 +++++++++++- ts/util/i18n/i18n.ts | 13 +------------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ts/types/Localizer.ts b/ts/types/Localizer.ts index f5d61f418..6b9c3d642 100644 --- a/ts/types/Localizer.ts +++ b/ts/types/Localizer.ts @@ -116,7 +116,7 @@ export type I18nMethods = { /** @see {@link window.i18n.stripped} */ stripped: ( ...[token, args]: GetMessageArgs - ) => R; + ) => R | T; /** @see {@link window.i18n.inEnglish} */ inEnglish: ( ...[token, args]: GetMessageArgs diff --git a/ts/util/i18n/functions/getMessage.ts b/ts/util/i18n/functions/getMessage.ts index fa9bf06d8..5fe86aebe 100644 --- a/ts/util/i18n/functions/getMessage.ts +++ b/ts/util/i18n/functions/getMessage.ts @@ -6,10 +6,13 @@ import { GetMessageArgs, ArgsRecord, DictionaryWithoutPluralStrings, + SetupI18nReturnType, } from '../../../types/Localizer'; import { i18nLog } from '../shared'; import { formatMessageWithArgs } from './formatMessageWithArgs'; import { getRawMessage } from './getRawMessage'; +import { inEnglish } from './inEnglish'; +import { stripped } from './stripped'; /** * Checks if a string contains a dynamic variable. @@ -39,7 +42,7 @@ const isStringWithArgs = '1 of 1 match' */ -export function getMessage( +function getMessageDefault( ...[token, args]: GetMessageArgs ): R | T { try { @@ -56,3 +59,10 @@ export function getMessage