Skip to content

Commit 20cd96e

Browse files
authored
fix: improve form type definition #3638 (#3669)
1 parent 553dff9 commit 20cd96e

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

components/form/Form.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineComponent, inject, provide, PropType, computed } from 'vue';
1+
import { defineComponent, inject, provide, PropType, computed, ExtractPropTypes } from 'vue';
22
import PropTypes from '../_util/vue-types';
33
import classNames from '../_util/classNames';
44
import warning from '../_util/warning';
@@ -43,7 +43,7 @@ export type ValidationRule = {
4343
trigger?: string;
4444
};
4545

46-
export const FormProps = {
46+
export const formProps = {
4747
layout: PropTypes.oneOf(tuple('horizontal', 'inline', 'vertical')),
4848
labelCol: { type: Object as PropType<ColProps> },
4949
wrapperCol: { type: Object as PropType<ColProps> },
@@ -64,14 +64,16 @@ export const FormProps = {
6464
validateTrigger: { type: [String, Array] as PropType<string | string[]> },
6565
};
6666

67+
export type FormProps = Partial<ExtractPropTypes<typeof formProps>>;
68+
6769
function isEqualName(name1: NamePath, name2: NamePath) {
6870
return isEqual(toArray(name1), toArray(name2));
6971
}
7072

7173
const Form = defineComponent({
7274
name: 'AForm',
7375
inheritAttrs: false,
74-
props: initDefaultProps(FormProps, {
76+
props: initDefaultProps(formProps, {
7577
layout: 'horizontal',
7678
hideRequiredMark: false,
7779
colon: true,

components/form/FormItem.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { inject, provide, PropType, defineComponent, computed, nextTick } from 'vue';
1+
import {
2+
inject,
3+
provide,
4+
PropType,
5+
defineComponent,
6+
computed,
7+
nextTick,
8+
ExtractPropTypes,
9+
} from 'vue';
210
import cloneDeep from 'lodash-es/cloneDeep';
311
import PropTypes from '../_util/vue-types';
412
import classNames from '../_util/classNames';
@@ -66,7 +74,7 @@ function getPropByPath(obj: any, namePathList: any, strict?: boolean) {
6674
v: tempObj ? tempObj[keyArr[i]] : undefined,
6775
};
6876
}
69-
export const FormItemProps = {
77+
export const formItemProps = {
7078
id: PropTypes.string,
7179
htmlFor: PropTypes.string,
7280
prefixCls: PropTypes.string,
@@ -89,12 +97,14 @@ export const FormItemProps = {
8997
messageVariables: { type: Object as PropType<Record<string, string>> },
9098
};
9199

100+
export type FormItemProps = Partial<ExtractPropTypes<typeof formItemProps>>;
101+
92102
export default defineComponent({
93103
name: 'AFormItem',
94104
mixins: [BaseMixin],
95105
inheritAttrs: false,
96106
__ANT_NEW_FORM_ITEM: true,
97-
props: FormItemProps,
107+
props: formItemProps,
98108
setup(props) {
99109
const FormContext = inject('FormContext', {}) as any;
100110
const fieldName = computed(() => props.name || props.prop);

components/form/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { App, Plugin } from 'vue';
22
import Form from './Form';
33

4-
export { FormProps } from './Form';
4+
export { FormProps, formProps } from './Form';
5+
export { FormItemProps, formItemProps } from './FormItem';
56

67
/* istanbul ignore next */
78
Form.install = function(app: App) {

0 commit comments

Comments
 (0)