From 219f3ab763fa40f261be72f4c1ca32c8d29712e0 Mon Sep 17 00:00:00 2001 From: Pedro Durek Date: Wed, 10 Nov 2021 19:45:34 -0700 Subject: [PATCH] Rename AppendKeys to KeysWithSeparator --- test/typescript/returnTypes.test.ts | 11 +++++++---- ts4.1/index.d.ts | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/test/typescript/returnTypes.test.ts b/test/typescript/returnTypes.test.ts index 6b0691aad..40a6e5c68 100644 --- a/test/typescript/returnTypes.test.ts +++ b/test/typescript/returnTypes.test.ts @@ -1,4 +1,4 @@ -import { AppendKeys, NormalizeByTypeOptions, NormalizeReturn, TFuncReturn } from 'react-i18next'; +import { KeysWithSeparator, NormalizeByTypeOptions, NormalizeReturn } from 'react-i18next'; // Test cases for TypeOptions['returnNull']: true type ReturnNull = NormalizeByTypeOptions; // Returns null @@ -33,21 +33,24 @@ const emptyStringValue2: ReturnEmptyString = ''; const nonEmptyStringValue2: ReturnEmptyString = 'non-empty-string'; // Test cases for TypeOptions['keySeparator']: '.' (default) -type DefaultCase = AppendKeys<'namespace', 'key' | 'key2'>; +type DefaultCase = KeysWithSeparator<'namespace', 'key' | 'key2'>; const defaultCaseExpectedResult = 'namespace.key'; const defaultCaseExpectedResult2 = 'namespace.key2'; const defaultCase: DefaultCase = defaultCaseExpectedResult; const defaultCase2: DefaultCase = defaultCaseExpectedResult2; // Test cases for TypeOptions['keySeparator']: '>>>' (arbitrary separator) -type ArbitrarySeparatorCase = AppendKeys<'namespace', 'key' | 'key2', '>>>'>; +type ArbitrarySeparatorCase = KeysWithSeparator<'namespace', 'key' | 'key2', '>>>'>; const arbitrarySeparatorExpectedResult = 'namespace>>>key'; const arbitrarySeparatorExpectedResult2 = 'namespace>>>key2'; const arbitrarySeparatorCase: ArbitrarySeparatorCase = arbitrarySeparatorExpectedResult; const arbitrarySeparatorCase2: ArbitrarySeparatorCase = arbitrarySeparatorExpectedResult2; // Test cases for TypeOptions['keySeparator']: false (nesting not supported) -interface MockDictionary { key: { nested: 'value' }; notNested: 'value' }; +interface MockDictionary { + key: { nested: 'value' }; + notNested: 'value'; +} type ReturnGivenKey = NormalizeReturn; const shouldBeGivenKey: ReturnGivenKey = 'key.nested'; diff --git a/ts4.1/index.d.ts b/ts4.1/index.d.ts index 1aef680b4..49c9dfc52 100644 --- a/ts4.1/index.d.ts +++ b/ts4.1/index.d.ts @@ -102,7 +102,7 @@ type WithOrWithoutPlural = TypeOptions['jsonFormat'] extends 'v4' : K; // Normalize single namespace -type KeysWithSeparator = `${K1 & +export type KeysWithSeparator = `${K1 & string}${S}${K2 & string}`; type KeysWithSeparator2 = KeysWithSeparator>; type Normalize2 = K extends keyof T