Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add nsSeparator to CustomTypeOptions #1471

Merged
merged 1 commit into from
Mar 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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