From d1555b3b9ed5e4fd3f5ce783b36664cd7fafae72 Mon Sep 17 00:00:00 2001 From: zhangfisher Date: Wed, 21 Aug 2024 18:07:34 +0800 Subject: [PATCH] update --- packages/core/src/field2.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/core/src/field2.tsx b/packages/core/src/field2.tsx index e1ec1e4..b591ff1 100644 --- a/packages/core/src/field2.tsx +++ b/packages/core/src/field2.tsx @@ -115,9 +115,11 @@ function createFieldProps(name:string,value:any,syncer:any,filedUpdater:any){ */ export type UnknownArray = readonly unknown[]; -type PickArrayItem = - T extends [infer First,...infer rest] - ? (First extends FormFieldBase ? PickArrayItem : R): R + +// 主类型,用于从数组中提取每个对象的 `value` 类型,并将其组合成一个元组类型 +type PickArrayItem = { + [K in keyof T]:T[K] extends { value: infer V } ? V : never +}; type FormFieldState = { [Name in keyof Fields]: @@ -137,8 +139,9 @@ const data = { ], a:{value:"aaaa"} } - -type ass=FormFieldState + +// 使用 PickArrayItem 类型来自动推断 data.fields 中每个成员的 `value` 类型 +type ass = PickArrayItem;