Skip to content

Commit

Permalink
fix: typescript error
Browse files Browse the repository at this point in the history
  • Loading branch information
charIeszhao committed Jul 19, 2024
1 parent 65e625e commit 84ca7ea
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions packages/phrases-experience/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import type en from './locales/en/index.js';

type FlattenKeys<T, Prefix extends string = ''> = {
[K in keyof T]: T[K] extends Record<string, unknown>
? `${Prefix}${string & K}.${FlattenKeys<T[K]>}`
: `${Prefix}${string & K}`;
}[keyof T];
type DecrementDepth<D extends number> = D extends 5
? 4
: D extends 4
? 3
: D extends 3
? 2
: D extends 2
? 1
: 0;

type FlattenKeys<T, Prefix extends string = '', Depth extends number = 5> = Depth extends 0
? never
: {
[K in keyof T]: T[K] extends Record<string, unknown>
? `${Prefix}${string & K}.${FlattenKeys<T[K], '', DecrementDepth<Depth>>}`
: `${Prefix}${string & K}`;
}[keyof T];

export type LocalePhrase = typeof en;

Expand Down

0 comments on commit 84ca7ea

Please sign in to comment.