From 3f066684f4dc3c88316fe3f3bf62f09932f4cbfa Mon Sep 17 00:00:00 2001 From: Pedro Durek Date: Tue, 22 Feb 2022 00:37:09 -0700 Subject: [PATCH] Fix never return with plurals (#1453) --- ts4.1/index.d.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ts4.1/index.d.ts b/ts4.1/index.d.ts index f671ee02..b8f203e1 100644 --- a/ts4.1/index.d.ts +++ b/ts4.1/index.d.ts @@ -95,8 +95,10 @@ declare module 'i18next' { } } +type PluralSuffix = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other'; + type WithOrWithoutPlural = TypeOptions['jsonFormat'] extends 'v4' - ? K extends `${infer B}_${'zero' | 'one' | 'two' | 'few' | 'many' | 'other'}` + ? K extends `${infer B}_${PluralSuffix}` ? B | K : K : K; @@ -150,6 +152,12 @@ export type NormalizeByTypeOptions< R = TypeOptionsFallback > = TypeOptionsFallback; +type StringIfPlural = TypeOptions['jsonFormat'] extends 'v4' + ? T extends `${string}_${PluralSuffix}` + ? string + : never + : never; + type NormalizeReturn< T, V, @@ -162,7 +170,7 @@ type NormalizeReturn< ? K extends keyof T ? NormalizeReturn : never - : never; + : StringIfPlural; type NormalizeMultiReturn = V extends `${infer N}:${infer R}` ? N extends keyof T