Skip to content

Commit

Permalink
Rename AppendKeys to KeysWithSeparator
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrodurek committed Nov 11, 2021
1 parent 4ca0e7a commit 219f3ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions test/typescript/returnTypes.test.ts
Original file line number Diff line number Diff line change
@@ -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<null, { returnNull: true }>; // Returns null
Expand Down Expand Up @@ -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<MockDictionary, 'key.nested', false>;
const shouldBeGivenKey: ReturnGivenKey = 'key.nested';
Expand Down
2 changes: 1 addition & 1 deletion ts4.1/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type WithOrWithoutPlural<K> = TypeOptions['jsonFormat'] extends 'v4'
: K;

// Normalize single namespace
type KeysWithSeparator<K1, K2, S extends string = TypeOptions['keySeparator']> = `${K1 &
export type KeysWithSeparator<K1, K2, S extends string = TypeOptions['keySeparator']> = `${K1 &
string}${S}${K2 & string}`;
type KeysWithSeparator2<K1, K2> = KeysWithSeparator<K1, Exclude<K2, keyof any[]>>;
type Normalize2<T, K = keyof T> = K extends keyof T
Expand Down

0 comments on commit 219f3ab

Please sign in to comment.