Skip to content

Commit

Permalink
Fix never return with plurals (#1453)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrodurek committed Feb 22, 2022
1 parent 97d5d07 commit 3f06668
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ts4.1/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ declare module 'i18next' {
}
}

type PluralSuffix = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';

type WithOrWithoutPlural<K> = TypeOptions['jsonFormat'] extends 'v4'
? K extends `${infer B}_${'zero' | 'one' | 'two' | 'few' | 'many' | 'other'}`
? K extends `${infer B}_${PluralSuffix}`
? B | K
: K
: K;
Expand Down Expand Up @@ -150,6 +152,12 @@ export type NormalizeByTypeOptions<
R = TypeOptionsFallback<TranslationValue, Options['returnEmptyString'], ''>
> = TypeOptionsFallback<R, Options['returnNull'], null>;

type StringIfPlural<T> = TypeOptions['jsonFormat'] extends 'v4'
? T extends `${string}_${PluralSuffix}`
? string
: never
: never;

type NormalizeReturn<
T,
V,
Expand All @@ -162,7 +170,7 @@ type NormalizeReturn<
? K extends keyof T
? NormalizeReturn<T[K], R>
: never
: never;
: StringIfPlural<keyof T>;

type NormalizeMultiReturn<T, V> = V extends `${infer N}:${infer R}`
? N extends keyof T
Expand Down

0 comments on commit 3f06668

Please sign in to comment.