From 5569708b82140c292e05a5b96bc5c54f24d082c6 Mon Sep 17 00:00:00 2001 From: reco_luan Date: Mon, 16 Dec 2024 02:08:10 +0800 Subject: [PATCH] fix: optimize ts type of getKitData --- packages/@revili/helpers/src/node/utils/kitData.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/@revili/helpers/src/node/utils/kitData.ts b/packages/@revili/helpers/src/node/utils/kitData.ts index f1fb1ba..01b7772 100644 --- a/packages/@revili/helpers/src/node/utils/kitData.ts +++ b/packages/@revili/helpers/src/node/utils/kitData.ts @@ -80,9 +80,13 @@ export async function initKitData(kitName: string): Promise { * Read kit data from data.json * @returns The kit data object, or null if data doesn't exist */ -export async function getKitData, K extends keyof T = never>( +export async function getKitData, K extends keyof (KitData & T)>( + prop: K +): Promise<(KitData & T)[K] | null> +export async function getKitData>(): Promise<(KitData & T) | null> +export async function getKitData, K extends keyof (KitData & T)>( prop?: K -): Promise { +): Promise<(KitData & T) | (KitData & T)[K] | null> { const { activeKit } = await getReviliConfig() const dataPath = await getKitDataFilePath(activeKit, 'data.json') @@ -91,13 +95,13 @@ export async function getKitData const data = JSON.parse(content) as KitData & T if (prop !== undefined) { - return data[prop] as K extends never ? (KitData & T) | null : T[K] | null + return data[prop] } - return data as K extends never ? (KitData & T) | null : T[K] | null + return data } catch (error) { console.error('Error reading kit data:', error) - return null as K extends never ? (KitData & T) | null : T[K] | null + return null } }