Skip to content

Commit

Permalink
Fix inference for specific keys (i18next#1215)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrodurek committed Dec 26, 2020
1 parent 8fa7101 commit a0c7458
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ts4.1/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ declare module 'i18next' {
}

// Normalize single namespace
type OmitArrayProps<T> = Exclude<T, keyof any[]>;
type AppendKeys<K1, K2> = `${K1 & string}.${OmitArrayProps<K2> & string}`;
type AppendKeys<K1, K2> = `${K1 & string}.${K2 & string}`;
type AppendKeys2<K1, K2> = `${K1 & string}.${Exclude<K2, keyof any[]> & string}`;
type Normalize2<T, K = keyof T> = K extends keyof T
? T[K] extends object
? AppendKeys<K, keyof T[K]> | AppendKeys<K, Normalize2<T[K]>>
? T[K] extends Record<string, any>
? T[K] extends readonly any[]
? AppendKeys2<K, keyof T[K]> | AppendKeys2<K, Normalize2<T[K]>>
: AppendKeys<K, keyof T[K]> | AppendKeys<K, Normalize2<T[K]>>
: never
: never;
type Normalize<T> = keyof T | Normalize2<T>;
Expand Down

0 comments on commit a0c7458

Please sign in to comment.