Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the name types of FormInstance are not inferred correctly #645

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/examples/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type FormData = {
};

export default () => {
const [form] = Form.useForm();
const [form] = Form.useForm<FormData>();

return (
<Form
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/initialValues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const formValue = {
};

export default () => {
const [form] = Form.useForm();
const [form] = Form.useForm<typeof formValue>();
const [show, setShow] = useState<boolean>(false);

return (
Expand Down
28 changes: 14 additions & 14 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export interface InternalFieldData extends Meta {
/**
* Used by `setFields` config
*/
export interface FieldData extends Partial<Omit<InternalFieldData, 'name'>> {
name: NamePath;
export interface FieldData<Values = any> extends Partial<Omit<InternalFieldData, 'name'>> {
name: NamePath<Values>;
}

export type RuleType =
Expand Down Expand Up @@ -251,21 +251,21 @@ export type GetFieldsValueConfig = { strict?: boolean; filter?: FilterFunc };

export interface FormInstance<Values = any> {
// Origin Form API
getFieldValue: (name: NamePath) => StoreValue;
getFieldValue: (name: NamePath<Values>) => StoreValue;
getFieldsValue: (() => Values) &
((nameList: NamePath[] | true, filterFunc?: FilterFunc) => any) &
((nameList: NamePath<Values>[] | 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<Values>) => string[];
getFieldsError: (nameList?: NamePath<Values>[]) => FieldError[];
getFieldWarning: (name: NamePath<Values>) => string[];
isFieldsTouched: ((nameList?: NamePath<Values>[], 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<Values>) => boolean;
isFieldValidating: (name: NamePath<Values>) => boolean;
isFieldsValidating: (nameList?: NamePath<Values>[]) => boolean;
resetFields: (fields?: NamePath<Values>[]) => void;
setFields: (fields: FieldData<Values>[]) => void;
setFieldValue: (name: NamePath<Values>, value: any) => void;
setFieldsValue: (values: RecursivePartial<Values>) => void;
validateFields: ValidateFields<Values>;

Expand Down