From 6ab06584ebda5b634f1d36923ca6c8a1f7cf07b0 Mon Sep 17 00:00:00 2001 From: dullathanol <327533967@qq.com> Date: Fri, 3 Apr 2026 13:36:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=87=BD=E6=95=B0=E5=BC=8F=20componentP?= =?UTF-8?q?rops=20=E6=8C=89=E5=B7=B2=E6=B3=A8=E5=86=8C=20component=20?= =?UTF-8?q?=E7=9A=84=20Props=20=E6=A0=A1=E9=AA=8C=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/adapter/form-schema.ts | 25 +++++++++++++------ .../web-antdv-next/src/adapter/form-schema.ts | 25 +++++++++++++------ apps/web-ele/src/adapter/form-schema.ts | 25 +++++++++++++------ apps/web-naive/src/adapter/form-schema.ts | 25 +++++++++++++------ apps/web-tdesign/src/adapter/form-schema.ts | 25 +++++++++++++------ playground/src/adapter/form-schema.ts | 25 +++++++++++++------ 6 files changed, 102 insertions(+), 48 deletions(-) diff --git a/apps/web-antd/src/adapter/form-schema.ts b/apps/web-antd/src/adapter/form-schema.ts index 2eef37e99..a759fe4c0 100644 --- a/apps/web-antd/src/adapter/form-schema.ts +++ b/apps/web-antd/src/adapter/form-schema.ts @@ -32,19 +32,28 @@ import type { import type { ComponentType } from './component'; +type ComponentPropsFnArgs = Parameters< + Extract< + NonNullable['componentProps']>, + (...args: any) => any + > +>; + /** - * 对象形式:使用适配器里为各 `component` 声明的 Props 类型 `P`; - * 与 `Record` 相交是为了满足核心库 `MaybeComponentProps` 的索引签名。 - * 函数形式:通过联合 `CoreFormSchema['componentProps']`,与表单核心对动态 `componentProps` 的约定保持一致。 + * 使用适配器里为各 `component` 声明的 Props 类型 `P`; + * 与 `Record` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。 */ -type SchemaComponentProps

= - | CoreFormSchema['componentProps'] +type ComponentProps

= + | (( + value: ComponentPropsFnArgs[0], + actions: ComponentPropsFnArgs[1], + ) => P & Record) | (P & Record); /** * 与 {@link ComponentType} 中注册的组件名一一对应,便于 Schema 上 `component` + `componentProps` 联动提示 */ -interface FormSchemaComponentPropsMap { +interface ComponentPropsMap { ApiCascader: ApiComponentSharedProps & CascaderProps; ApiSelect: ApiComponentSharedProps & SelectProps; ApiTreeSelect: ApiComponentSharedProps & TreeSelectProps; @@ -79,12 +88,12 @@ type BaseSchema = Omit< 'component' | 'componentProps' >; -type RegisteredName = keyof FormSchemaComponentPropsMap; +type RegisteredName = keyof ComponentPropsMap; type DiscriminatedFormSchema = { [K in RegisteredName]: BaseSchema & { component: K; - componentProps?: SchemaComponentProps; + componentProps?: ComponentProps; }; }[RegisteredName]; diff --git a/apps/web-antdv-next/src/adapter/form-schema.ts b/apps/web-antdv-next/src/adapter/form-schema.ts index bbae3d18c..c2adcc2dc 100644 --- a/apps/web-antdv-next/src/adapter/form-schema.ts +++ b/apps/web-antdv-next/src/adapter/form-schema.ts @@ -32,19 +32,28 @@ import type { import type { ComponentType } from './component'; +type ComponentPropsFnArgs = Parameters< + Extract< + NonNullable['componentProps']>, + (...args: any) => any + > +>; + /** - * 对象形式:使用适配器里为各 `component` 声明的 Props 类型 `P`; - * 与 `Record` 相交是为了满足核心库 `MaybeComponentProps` 的索引签名。 - * 函数形式:通过联合 `CoreFormSchema['componentProps']`,与表单核心对动态 `componentProps` 的约定保持一致。 + * 使用适配器里为各 `component` 声明的 Props 类型 `P`; + * 与 `Record` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。 */ -type SchemaComponentProps

= - | CoreFormSchema['componentProps'] +type ComponentProps

= + | (( + value: ComponentPropsFnArgs[0], + actions: ComponentPropsFnArgs[1], + ) => P & Record) | (P & Record); /** * 与 {@link ComponentType} 中注册的组件名一一对应,便于 Schema 上 `component` + `componentProps` 联动提示 */ -interface FormSchemaComponentPropsMap { +interface ComponentPropsMap { ApiCascader: ApiComponentSharedProps & CascaderProps; ApiSelect: ApiComponentSharedProps & SelectProps; ApiTreeSelect: ApiComponentSharedProps & TreeSelectProps; @@ -79,12 +88,12 @@ type BaseSchema = Omit< 'component' | 'componentProps' >; -type RegisteredName = keyof FormSchemaComponentPropsMap; +type RegisteredName = keyof ComponentPropsMap; type DiscriminatedFormSchema = { [K in RegisteredName]: BaseSchema & { component: K; - componentProps?: SchemaComponentProps; + componentProps?: ComponentProps; }; }[RegisteredName]; diff --git a/apps/web-ele/src/adapter/form-schema.ts b/apps/web-ele/src/adapter/form-schema.ts index 740ad34d0..770cc61d0 100644 --- a/apps/web-ele/src/adapter/form-schema.ts +++ b/apps/web-ele/src/adapter/form-schema.ts @@ -27,19 +27,28 @@ import type { ComponentType } from './component'; type ElTreeSelectSchemaProps = InstanceType['$props']; type ElTimePickerSchemaProps = InstanceType['$props']; +type ComponentPropsFnArgs = Parameters< + Extract< + NonNullable['componentProps']>, + (...args: any) => any + > +>; + /** - * 对象形式:使用适配器里为各 `component` 声明的 Props 类型 `P`; - * 与 `Record` 相交是为了满足核心库 `MaybeComponentProps` 的索引签名。 - * 函数形式:通过联合 `CoreFormSchema['componentProps']`,与表单核心对动态 `componentProps` 的约定保持一致。 + * 使用适配器里为各 `component` 声明的 Props 类型 `P`; + * 与 `Record` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。 */ -type SchemaComponentProps

= - | CoreFormSchema['componentProps'] +type ComponentProps

= + | (( + value: ComponentPropsFnArgs[0], + actions: ComponentPropsFnArgs[1], + ) => P & Record) | (P & Record); /** * 与 {@link ComponentType} 中注册的组件名一一对应,便于 Schema 上 `component` + `componentProps` 联动提示 */ -interface FormSchemaComponentPropsMap { +interface ComponentPropsMap { ApiSelect: ApiComponentSharedProps & SelectV2Props; ApiTreeSelect: ApiComponentSharedProps & ElTreeSelectSchemaProps; Checkbox: CheckboxProps; @@ -63,12 +72,12 @@ type BaseSchema = Omit< 'component' | 'componentProps' >; -type RegisteredName = keyof FormSchemaComponentPropsMap; +type RegisteredName = keyof ComponentPropsMap; type DiscriminatedFormSchema = { [K in RegisteredName]: BaseSchema & { component: K; - componentProps?: SchemaComponentProps; + componentProps?: ComponentProps; }; }[RegisteredName]; diff --git a/apps/web-naive/src/adapter/form-schema.ts b/apps/web-naive/src/adapter/form-schema.ts index 0172358ef..f4f062b4a 100644 --- a/apps/web-naive/src/adapter/form-schema.ts +++ b/apps/web-naive/src/adapter/form-schema.ts @@ -24,19 +24,28 @@ import type { import type { ComponentType } from './component'; +type ComponentPropsFnArgs = Parameters< + Extract< + NonNullable['componentProps']>, + (...args: any) => any + > +>; + /** - * 对象形式:使用适配器里为各 `component` 声明的 Props 类型 `P`; - * 与 `Record` 相交是为了满足核心库 `MaybeComponentProps` 的索引签名。 - * 函数形式:通过联合 `CoreFormSchema['componentProps']`,与表单核心对动态 `componentProps` 的约定保持一致。 + * 使用适配器里为各 `component` 声明的 Props 类型 `P`; + * 与 `Record` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。 */ -type SchemaComponentProps

= - | CoreFormSchema['componentProps'] +type ComponentProps

= + | (( + value: ComponentPropsFnArgs[0], + actions: ComponentPropsFnArgs[1], + ) => P & Record) | (P & Record); /** * 与 {@link ComponentType} 中注册的组件名一一对应,便于 Schema 上 `component` + `componentProps` 联动提示 */ -interface FormSchemaComponentPropsMap { +interface ComponentPropsMap { ApiSelect: ApiComponentSharedProps & SelectProps; ApiTreeSelect: ApiComponentSharedProps & TreeSelectProps; Checkbox: CheckboxProps; @@ -60,12 +69,12 @@ type BaseSchema = Omit< 'component' | 'componentProps' >; -type RegisteredName = keyof FormSchemaComponentPropsMap; +type RegisteredName = keyof ComponentPropsMap; type DiscriminatedFormSchema = { [K in RegisteredName]: BaseSchema & { component: K; - componentProps?: SchemaComponentProps; + componentProps?: ComponentProps; }; }[RegisteredName]; diff --git a/apps/web-tdesign/src/adapter/form-schema.ts b/apps/web-tdesign/src/adapter/form-schema.ts index 1211af135..34d7641d6 100644 --- a/apps/web-tdesign/src/adapter/form-schema.ts +++ b/apps/web-tdesign/src/adapter/form-schema.ts @@ -30,19 +30,28 @@ import type { import type { ComponentType } from './component'; +type ComponentPropsFnArgs = Parameters< + Extract< + NonNullable['componentProps']>, + (...args: any) => any + > +>; + /** - * 对象形式:使用适配器里为各 `component` 声明的 Props 类型 `P`; - * 与 `Record` 相交是为了满足核心库 `MaybeComponentProps` 的索引签名。 - * 函数形式:通过联合 `CoreFormSchema['componentProps']`,与表单核心对动态 `componentProps` 的约定保持一致。 + * 使用适配器里为各 `component` 声明的 Props 类型 `P`; + * 与 `Record` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。 */ -type SchemaComponentProps

= - | CoreFormSchema['componentProps'] +type ComponentProps

= + | (( + value: ComponentPropsFnArgs[0], + actions: ComponentPropsFnArgs[1], + ) => P & Record) | (P & Record); /** * 与 {@link ComponentType} 中注册的组件名一一对应,便于 Schema 上 `component` + `componentProps` 联动提示 */ -interface FormSchemaComponentPropsMap { +interface ComponentPropsMap { ApiSelect: ApiComponentSharedProps & SelectProps; ApiTreeSelect: ApiComponentSharedProps & TreeSelectProps; AutoComplete: AutoCompleteProps; @@ -73,12 +82,12 @@ type BaseSchema = Omit< 'component' | 'componentProps' >; -type RegisteredName = keyof FormSchemaComponentPropsMap; +type RegisteredName = keyof ComponentPropsMap; type DiscriminatedFormSchema = { [K in RegisteredName]: BaseSchema & { component: K; - componentProps?: SchemaComponentProps; + componentProps?: ComponentProps; }; }[RegisteredName]; diff --git a/playground/src/adapter/form-schema.ts b/playground/src/adapter/form-schema.ts index 2eef37e99..a759fe4c0 100644 --- a/playground/src/adapter/form-schema.ts +++ b/playground/src/adapter/form-schema.ts @@ -32,19 +32,28 @@ import type { import type { ComponentType } from './component'; +type ComponentPropsFnArgs = Parameters< + Extract< + NonNullable['componentProps']>, + (...args: any) => any + > +>; + /** - * 对象形式:使用适配器里为各 `component` 声明的 Props 类型 `P`; - * 与 `Record` 相交是为了满足核心库 `MaybeComponentProps` 的索引签名。 - * 函数形式:通过联合 `CoreFormSchema['componentProps']`,与表单核心对动态 `componentProps` 的约定保持一致。 + * 使用适配器里为各 `component` 声明的 Props 类型 `P`; + * 与 `Record` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。 */ -type SchemaComponentProps

= - | CoreFormSchema['componentProps'] +type ComponentProps

= + | (( + value: ComponentPropsFnArgs[0], + actions: ComponentPropsFnArgs[1], + ) => P & Record) | (P & Record); /** * 与 {@link ComponentType} 中注册的组件名一一对应,便于 Schema 上 `component` + `componentProps` 联动提示 */ -interface FormSchemaComponentPropsMap { +interface ComponentPropsMap { ApiCascader: ApiComponentSharedProps & CascaderProps; ApiSelect: ApiComponentSharedProps & SelectProps; ApiTreeSelect: ApiComponentSharedProps & TreeSelectProps; @@ -79,12 +88,12 @@ type BaseSchema = Omit< 'component' | 'componentProps' >; -type RegisteredName = keyof FormSchemaComponentPropsMap; +type RegisteredName = keyof ComponentPropsMap; type DiscriminatedFormSchema = { [K in RegisteredName]: BaseSchema & { component: K; - componentProps?: SchemaComponentProps; + componentProps?: ComponentProps; }; }[RegisteredName];