diff --git a/test/typescript/custom-types/custom-types.d.ts b/test/typescript/custom-types/custom-types.d.ts index 5fc5e8e4..ca7dbdf1 100644 --- a/test/typescript/custom-types/custom-types.d.ts +++ b/test/typescript/custom-types/custom-types.d.ts @@ -14,6 +14,13 @@ declare module 'react-i18next' { barfoo: 'barfoo'; }; }; + plurals: { + foo_zero: 'foo'; + foo_one: 'foo'; + foo_two: 'foo'; + foo_many: 'foo'; + foo_other: 'foo'; + }; }; } } diff --git a/test/typescript/custom-types/useTranslation.test.tsx b/test/typescript/custom-types/useTranslation.test.tsx index b2f0b300..9d6595e8 100644 --- a/test/typescript/custom-types/useTranslation.test.tsx +++ b/test/typescript/custom-types/useTranslation.test.tsx @@ -43,6 +43,16 @@ function keyPrefixOption() { return <>{t('barfoo')}; } +function jsonFormatV4Plurals() { + const [t] = useTranslation('plurals'); + return ( + <> + {t('foo')} + {t('foo_one')} + + ); +} + function expectErrorWhenNamespaceDoesNotExist() { // @ts-expect-error const [t] = useTranslation('fake'); diff --git a/ts4.1/index.d.ts b/ts4.1/index.d.ts index 46603fc9..5f5bb61e 100644 --- a/ts4.1/index.d.ts +++ b/ts4.1/index.d.ts @@ -35,8 +35,10 @@ export interface Resources {} * declare module 'react-i18next' { * interface CustomTypeOptions { * defaultNS: 'custom'; - * returnNull: false, - * returnEmptyString: false, + * returnNull: false; + * returnEmptyString: false; + * keySeparator: '.'; + * jsonFormat: 'v4'; * resources: { * custom: { * foo: 'foo'; @@ -56,6 +58,7 @@ type TypeOptions = MergeBy< returnEmptyString: true; keySeparator: '.'; defaultNS: 'translation'; + jsonFormat: 'v4'; resources: Resources; }, CustomTypeOptions @@ -92,6 +95,12 @@ declare module 'i18next' { } } +type WithOrWithoutPlural = TypeOptions['jsonFormat'] extends 'v4' + ? K extends `${infer B}_${'zero' | 'one' | 'two' | 'few' | 'many' | 'other'}` + ? B | K + : K + : K; + // Normalize single namespace type AppendKeys = `${K1 & string}${S}${K2 & string}`; @@ -100,11 +109,11 @@ type AppendKeys2 = `${K1 type Normalize2 = K extends keyof T ? T[K] extends Record ? T[K] extends readonly any[] - ? AppendKeys2 | AppendKeys2> - : AppendKeys | AppendKeys> + ? AppendKeys2> | AppendKeys2> + : AppendKeys> | AppendKeys> : never : never; -type Normalize = keyof T | Normalize2; +type Normalize = WithOrWithoutPlural | Normalize2; // Normalize multiple namespaces type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void