Skip to content

Commit

Permalink
Add nsSeparator to CustomTypeOptions (#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrodurek committed Mar 13, 2022
1 parent 6080bad commit 4ff2985
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ts4.1/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface Resources {}
* defaultNS: 'custom';
* returnNull: false;
* returnEmptyString: false;
* nsSeparator: ':';
* keySeparator: '.';
* jsonFormat: 'v4';
* resources: {
Expand All @@ -57,6 +58,7 @@ type TypeOptions = MergeBy<
returnNull: true;
returnEmptyString: true;
keySeparator: '.';
nsSeparator: ':';
defaultNS: 'translation';
jsonFormat: 'v4';
resources: Resources;
Expand Down Expand Up @@ -121,15 +123,16 @@ type Normalize2<T, K = keyof T> = K extends keyof T
type Normalize<T> = WithOrWithoutPlural<keyof T> | Normalize2<T>;

// Normalize multiple namespaces
type KeyWithNSSeparator<N, K, S extends string = TypeOptions['nsSeparator']> = `${N &
string}${S}${K & string}`;
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void
? I
: never;
type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => infer R
? R
: never;
type AppendNS<N, K> = `${N & string}:${K & string}`;
type NormalizeMulti<T, U extends keyof T, L = LastOf<U>> = L extends U
? AppendNS<L, Normalize<T[L]>> | NormalizeMulti<T, Exclude<U, L>>
? KeyWithNSSeparator<L, Normalize<T[L]>> | NormalizeMulti<T, Exclude<U, L>>
: never;

interface CustomTypeParameters {
Expand Down

0 comments on commit 4ff2985

Please sign in to comment.