Skip to content

Commit 72f8277

Browse files
committed
feat: export formInstance type
1 parent 8943595 commit 72f8277

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

components/components.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export { default as Drawer } from './drawer';
7373
export type { EmptyProps } from './empty';
7474
export { default as Empty } from './empty';
7575

76-
export type { FormProps, FormItemProps } from './form';
76+
export type { FormProps, FormItemProps, FormInstance } from './form';
7777
export { default as Form, FormItem, FormItemRest } from './form';
7878

7979
export { default as Grid } from './grid';

components/form/Form.tsx

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PropType, ExtractPropTypes, HTMLAttributes } from 'vue';
1+
import type { PropType, ExtractPropTypes, HTMLAttributes, ComponentPublicInstance } from 'vue';
22
import { defineComponent, computed, watch, ref } from 'vue';
33
import PropTypes from '../_util/vue-types';
44
import classNames from '../_util/classNames';
@@ -89,6 +89,29 @@ export const formProps = {
8989

9090
export type FormProps = Partial<ExtractPropTypes<typeof formProps>>;
9191

92+
export type FormExpose = {
93+
resetFields: (name?: NamePath) => void;
94+
clearValidate: (name?: NamePath) => void;
95+
validateFields: (
96+
nameList?: NamePath[],
97+
options?: ValidateOptions,
98+
) => Promise<{
99+
[key: string]: any;
100+
}>;
101+
getFieldsValue: (nameList?: InternalNamePath[] | true) => {
102+
[key: string]: any;
103+
};
104+
validate: (
105+
nameList?: NamePath[],
106+
options?: ValidateOptions,
107+
) => Promise<{
108+
[key: string]: any;
109+
}>;
110+
scrollToField: (name: NamePath, options?: {}) => void;
111+
};
112+
113+
export type FormInstance = ComponentPublicInstance<FormProps, FormExpose>;
114+
92115
function isEqualName(name1: NamePath, name2: NamePath) {
93116
return isEqual(toArray(name1), toArray(name2));
94117
}
@@ -328,15 +351,14 @@ const Form = defineComponent({
328351
});
329352
}
330353
};
331-
332354
expose({
333355
resetFields,
334356
clearValidate,
335357
validateFields,
336358
getFieldsValue,
337359
validate,
338360
scrollToField,
339-
});
361+
} as FormExpose);
340362

341363
useProvideForm({
342364
model: computed(() => props.model),

components/form/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import useForm from './useForm';
55
import FormItemRest, { useInjectFormItemContext } from './FormItemContext';
66
export type { Rule, RuleObject } from './interface';
77

8-
export type { FormProps } from './Form';
8+
export type { FormProps, FormInstance } from './Form';
99
export type { FormItemProps } from './FormItem';
1010

1111
Form.useInjectFormItemContext = useInjectFormItemContext;

0 commit comments

Comments
 (0)