From 39c1da26ee944a9c359a4f4a0aa22f0bd6a89c26 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 17 Jan 2024 10:44:30 +0800 Subject: [PATCH] fix: the name types of `FormInstance` are not inferred correctly --- docs/examples/basic.tsx | 2 +- docs/examples/initialValues.tsx | 2 +- src/interface.ts | 28 ++++++++++++++-------------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/examples/basic.tsx b/docs/examples/basic.tsx index 48a46fc14..497ef8f48 100644 --- a/docs/examples/basic.tsx +++ b/docs/examples/basic.tsx @@ -9,7 +9,7 @@ type FormData = { }; export default () => { - const [form] = Form.useForm(); + const [form] = Form.useForm(); return (
{ - const [form] = Form.useForm(); + const [form] = Form.useForm(); const [show, setShow] = useState(false); return ( diff --git a/src/interface.ts b/src/interface.ts index 723998a61..af35aae6a 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -24,8 +24,8 @@ export interface InternalFieldData extends Meta { /** * Used by `setFields` config */ -export interface FieldData extends Partial> { - name: NamePath; +export interface FieldData extends Partial> { + name: NamePath; } export type RuleType = @@ -251,21 +251,21 @@ export type GetFieldsValueConfig = { strict?: boolean; filter?: FilterFunc }; export interface FormInstance { // Origin Form API - getFieldValue: (name: NamePath) => StoreValue; + getFieldValue: (name: NamePath) => StoreValue; getFieldsValue: (() => Values) & - ((nameList: NamePath[] | true, filterFunc?: FilterFunc) => any) & + ((nameList: NamePath[] | true, filterFunc?: FilterFunc) => any) & ((config: GetFieldsValueConfig) => any); - getFieldError: (name: NamePath) => string[]; - getFieldsError: (nameList?: NamePath[]) => FieldError[]; - getFieldWarning: (name: NamePath) => string[]; - isFieldsTouched: ((nameList?: NamePath[], allFieldsTouched?: boolean) => boolean) & + getFieldError: (name: NamePath) => string[]; + getFieldsError: (nameList?: NamePath[]) => FieldError[]; + getFieldWarning: (name: NamePath) => string[]; + isFieldsTouched: ((nameList?: NamePath[], allFieldsTouched?: boolean) => boolean) & ((allFieldsTouched?: boolean) => boolean); - isFieldTouched: (name: NamePath) => boolean; - isFieldValidating: (name: NamePath) => boolean; - isFieldsValidating: (nameList?: NamePath[]) => boolean; - resetFields: (fields?: NamePath[]) => void; - setFields: (fields: FieldData[]) => void; - setFieldValue: (name: NamePath, value: any) => void; + isFieldTouched: (name: NamePath) => boolean; + isFieldValidating: (name: NamePath) => boolean; + isFieldsValidating: (nameList?: NamePath[]) => boolean; + resetFields: (fields?: NamePath[]) => void; + setFields: (fields: FieldData[]) => void; + setFieldValue: (name: NamePath, value: any) => void; setFieldsValue: (values: RecursivePartial) => void; validateFields: ValidateFields;