From 9024dd5cc269aacfc97e7b996160b11527be64c2 Mon Sep 17 00:00:00 2001 From: Charles Zhao Date: Fri, 19 Jul 2024 16:11:37 +0800 Subject: [PATCH] fix: fix typescript type error in experience phrases --- packages/phrases-experience/src/types.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/phrases-experience/src/types.ts b/packages/phrases-experience/src/types.ts index 3e24bfff0..de7e4a903 100644 --- a/packages/phrases-experience/src/types.ts +++ b/packages/phrases-experience/src/types.ts @@ -1,10 +1,17 @@ import type en from './locales/en/index.js'; -type FlattenKeys = { - [K in keyof T]: T[K] extends Record - ? `${Prefix}${string & K}.${FlattenKeys}` - : `${Prefix}${string & K}`; -}[keyof T]; +type FlattenKeys< + T, + Prefix extends string = '', + D extends number = 11, // Depth limit is actually 10, since the initial value of A is [0] + A extends unknown[] = [0], +> = A['length'] extends D + ? never + : { + [K in keyof T]: T[K] extends Record + ? `${Prefix}${string & K}.${FlattenKeys}` + : `${Prefix}${string & K}`; + }[keyof T]; export type LocalePhrase = typeof en;