Skip to content

Commit 1646421

Browse files
committed
feat: update ts type
1 parent 55b9ab5 commit 1646421

22 files changed

+126
-94
lines changed

components/_util/EventInterface.ts

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export type KeyboardEventHandler = (e: KeyboardEvent) => void;
44
export type CompositionEventHandler = (e: CompositionEvent) => void;
55
export type ClipboardEventHandler = (e: ClipboardEvent) => void;
66
export type ChangeEventHandler = (e: ChangeEvent) => void;
7-
87
export type ChangeEvent = Event & {
98
target: {
109
value?: string | undefined;

components/components.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export {
9999
LayoutContent,
100100
} from './layout';
101101

102-
export type { ListProps } from './list';
102+
export type { ListProps, ListItemProps, ListItemMetaProps } from './list';
103103
export { default as List, ListItem, ListItemMeta } from './list';
104104

105105
export type { MessageArgsProps } from './message';

components/form/Form.tsx

+11-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type {
2323
ValidateErrorEntity,
2424
ValidateOptions,
2525
Callbacks,
26+
ValidateMessages,
2627
} from './interface';
2728
import { useInjectSize } from '../_util/hooks/useSize';
2829
import useConfigInject from '../_util/hooks/useConfigInject';
@@ -60,7 +61,7 @@ export type ValidationRule = {
6061
trigger?: string;
6162
};
6263

63-
export const formProps = {
64+
export const formProps = () => ({
6465
layout: PropTypes.oneOf(tuple('horizontal', 'inline', 'vertical')),
6566
labelCol: { type: Object as PropType<ColProps & HTMLAttributes> },
6667
wrapperCol: { type: Object as PropType<ColProps & HTMLAttributes> },
@@ -73,11 +74,14 @@ export const formProps = {
7374
hideRequiredMark: { type: Boolean, default: undefined },
7475
model: PropTypes.object,
7576
rules: { type: Object as PropType<{ [k: string]: ValidationRule[] | ValidationRule }> },
76-
validateMessages: PropTypes.object,
77+
validateMessages: {
78+
type: Object as PropType<ValidateMessages>,
79+
default: undefined as ValidateMessages,
80+
},
7781
validateOnRuleChange: { type: Boolean, default: undefined },
7882
// 提交失败自动滚动到第一个错误字段
7983
scrollToFirstError: { type: [Boolean, Object] as PropType<boolean | Options> },
80-
onSubmit: Function,
84+
onSubmit: Function as PropType<(e: Event) => void>,
8185
name: String,
8286
validateTrigger: { type: [String, Array] as PropType<string | string[]> },
8387
size: { type: String as PropType<SizeType> },
@@ -86,9 +90,9 @@ export const formProps = {
8690
onFinish: { type: Function as PropType<Callbacks['onFinish']> },
8791
onFinishFailed: { type: Function as PropType<Callbacks['onFinishFailed']> },
8892
onValidate: { type: Function as PropType<Callbacks['onValidate']> },
89-
};
93+
});
9094

91-
export type FormProps = Partial<ExtractPropTypes<typeof formProps>>;
95+
export type FormProps = Partial<ExtractPropTypes<ReturnType<typeof formProps>>>;
9296

9397
export type FormExpose = {
9498
resetFields: (name?: NamePath) => void;
@@ -120,14 +124,14 @@ function isEqualName(name1: NamePath, name2: NamePath) {
120124
const Form = defineComponent({
121125
name: 'AForm',
122126
inheritAttrs: false,
123-
props: initDefaultProps(formProps, {
127+
props: initDefaultProps(formProps(), {
124128
layout: 'horizontal',
125129
hideRequiredMark: false,
126130
colon: true,
127131
}),
128132
Item: FormItem,
129133
useForm,
130-
emits: ['finishFailed', 'submit', 'finish', 'validate'],
134+
// emits: ['finishFailed', 'submit', 'finish', 'validate'],
131135
setup(props, { emit, slots, expose, attrs }) {
132136
const size = useInjectSize(props);
133137
const { prefixCls, direction, form: contextForm } = useConfigInject('form', props);

components/form/FormItem.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { toArray } from './utils/typeUtil';
2727
import { warning } from '../vc-util/warning';
2828
import find from 'lodash-es/find';
2929
import { tuple } from '../_util/type';
30-
import type { InternalNamePath, RuleError, RuleObject, ValidateOptions } from './interface';
30+
import type { InternalNamePath, Rule, RuleError, RuleObject, ValidateOptions } from './interface';
3131
import useConfigInject from '../_util/hooks/useConfigInject';
3232
import { useInjectForm } from './context';
3333
import FormItemLabel from './FormItemLabel';
@@ -81,7 +81,7 @@ function getPropByPath(obj: any, namePathList: any, strict?: boolean) {
8181
v: tempObj ? tempObj[keyArr[i]] : undefined,
8282
};
8383
}
84-
export const formItemProps = {
84+
export const formItemProps = () => ({
8585
htmlFor: String,
8686
prefixCls: String,
8787
label: PropTypes.any,
@@ -94,7 +94,7 @@ export const formItemProps = {
9494
labelAlign: PropTypes.oneOf(tuple('left', 'right')),
9595
prop: { type: [String, Number, Array] as PropType<string | number | Array<string | number>> },
9696
name: { type: [String, Number, Array] as PropType<string | number | Array<string | number>> },
97-
rules: PropTypes.oneOfType([Array, Object]),
97+
rules: [Array, Object] as PropType<Rule[] | Rule>,
9898
autoLink: { type: Boolean, default: true },
9999
required: { type: Boolean, default: undefined },
100100
validateFirst: { type: Boolean, default: undefined },
@@ -103,9 +103,9 @@ export const formItemProps = {
103103
messageVariables: { type: Object as PropType<Record<string, string>> },
104104
hidden: Boolean,
105105
noStyle: Boolean,
106-
};
106+
});
107107

108-
export type FormItemProps = Partial<ExtractPropTypes<typeof formItemProps>>;
108+
export type FormItemProps = Partial<ExtractPropTypes<ReturnType<typeof formItemProps>>>;
109109

110110
export type FormItemExpose = {
111111
onFieldBlur: () => void;
@@ -125,7 +125,7 @@ export default defineComponent({
125125
name: 'AFormItem',
126126
inheritAttrs: false,
127127
__ANT_NEW_FORM_ITEM: true,
128-
props: formItemProps,
128+
props: formItemProps(),
129129
slots: ['help', 'label', 'extra'],
130130
setup(props, { slots, attrs, expose }) {
131131
warning(props.prop === undefined, `\`prop\` is deprecated. Please use \`name\` instead.`);

components/grid/Col.tsx

+28-7
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,34 @@ export const colProps = () => ({
3434
offset: [String, Number],
3535
push: [String, Number],
3636
pull: [String, Number],
37-
xs: { type: [String, Number, Object] as PropType<string | number | ColSize> },
38-
sm: { type: [String, Number, Object] as PropType<string | number | ColSize> },
39-
md: { type: [String, Number, Object] as PropType<string | number | ColSize> },
40-
lg: { type: [String, Number, Object] as PropType<string | number | ColSize> },
41-
xl: { type: [String, Number, Object] as PropType<string | number | ColSize> },
42-
xxl: { type: [String, Number, Object] as PropType<string | number | ColSize> },
43-
xxxl: { type: [String, Number, Object] as PropType<string | number | ColSize> },
37+
xs: {
38+
type: [String, Number, Object] as PropType<string | number | ColSize>,
39+
default: undefined as string | number | ColSize,
40+
},
41+
sm: {
42+
type: [String, Number, Object] as PropType<string | number | ColSize>,
43+
default: undefined as string | number | ColSize,
44+
},
45+
md: {
46+
type: [String, Number, Object] as PropType<string | number | ColSize>,
47+
default: undefined as string | number | ColSize,
48+
},
49+
lg: {
50+
type: [String, Number, Object] as PropType<string | number | ColSize>,
51+
default: undefined as string | number | ColSize,
52+
},
53+
xl: {
54+
type: [String, Number, Object] as PropType<string | number | ColSize>,
55+
default: undefined as string | number | ColSize,
56+
},
57+
xxl: {
58+
type: [String, Number, Object] as PropType<string | number | ColSize>,
59+
default: undefined as string | number | ColSize,
60+
},
61+
xxxl: {
62+
type: [String, Number, Object] as PropType<string | number | ColSize>,
63+
default: undefined as string | number | ColSize,
64+
},
4465
prefixCls: String,
4566
flex: [String, Number],
4667
});

components/image/PreviewGroup.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import PreviewGroup from '../vc-image/src/PreviewGroup';
22
import { computed, defineComponent } from 'vue';
3-
import PropTypes from '../_util/vue-types';
43
import useConfigInject from '../_util/hooks/useConfigInject';
54

65
const InternalPreviewGroup = defineComponent({
76
name: 'AImagePreviewGroup',
87
inheritAttrs: false,
9-
props: { previewPrefixCls: PropTypes.string },
8+
props: { previewPrefixCls: String },
109
setup(props, { attrs, slots }) {
1110
const { getPrefixCls } = useConfigInject('image', props);
1211
const prefixCls = computed(() => getPrefixCls('image-preview', props.previewPrefixCls));

components/image/index.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import useConfigInject from '../_util/hooks/useConfigInject';
66
import PreviewGroup from './PreviewGroup';
77

88
export type ImageProps = Partial<
9-
ExtractPropTypes<typeof imageProps> & Omit<ImgHTMLAttributes, 'placeholder' | 'onClick'>
9+
ExtractPropTypes<ReturnType<typeof imageProps>> &
10+
Omit<ImgHTMLAttributes, 'placeholder' | 'onClick'>
1011
>;
1112
const Image = defineComponent<ImageProps>({
1213
name: 'AImage',
1314
inheritAttrs: false,
14-
props: imageProps as any,
15+
props: imageProps() as any,
1516
setup(props, { slots, attrs }) {
1617
const { prefixCls } = useConfigInject('image', props);
1718
return () => {

components/input-number/index.tsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import { cloneElement } from '../_util/vnode';
1111
import omit from '../_util/omit';
1212
import PropTypes from '../_util/vue-types';
1313
import isValidValue from '../_util/isValidValue';
14-
export const inputNumberProps = {
15-
...baseInputNumberProps,
14+
const baseProps = baseInputNumberProps();
15+
export const inputNumberProps = () => ({
16+
...baseProps,
1617
size: { type: String as PropType<SizeType> },
1718
bordered: { type: Boolean, default: true },
1819
placeholder: String,
@@ -22,16 +23,16 @@ export const inputNumberProps = {
2223
addonBefore: PropTypes.any,
2324
addonAfter: PropTypes.any,
2425
prefix: PropTypes.any,
25-
'update:value': baseInputNumberProps.onChange,
26-
};
26+
'update:value': baseProps.onChange,
27+
});
2728

28-
export type InputNumberProps = Partial<ExtractPropTypes<typeof inputNumberProps>>;
29+
export type InputNumberProps = Partial<ExtractPropTypes<ReturnType<typeof inputNumberProps>>>;
2930

3031
const InputNumber = defineComponent({
3132
name: 'AInputNumber',
3233
inheritAttrs: false,
33-
props: inputNumberProps,
34-
emits: ['focus', 'blur', 'change', 'input', 'update:value'],
34+
props: inputNumberProps(),
35+
// emits: ['focus', 'blur', 'change', 'input', 'update:value'],
3536
slots: ['addonBefore', 'addonAfter', 'prefix'],
3637
setup(props, { emit, expose, attrs, slots }) {
3738
const formItemContext = useInjectFormItemContext();

components/input-number/src/InputNumber.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const getDecimalIfValidate = (value: ValueType) => {
3434
return decimal.isInvalidate() ? null : decimal;
3535
};
3636

37-
export const inputNumberProps = {
37+
export const inputNumberProps = () => ({
3838
/** value will show as string */
3939
stringMode: { type: Boolean as PropType<boolean> },
4040

@@ -76,12 +76,12 @@ export const inputNumberProps = {
7676
},
7777
onBlur: { type: Function as PropType<(e: InputEvent) => void> },
7878
onFocus: { type: Function as PropType<(e: InputEvent) => void> },
79-
};
79+
});
8080

8181
export default defineComponent({
8282
name: 'InnerInputNumber',
8383
inheritAttrs: false,
84-
props: inputNumberProps,
84+
props: inputNumberProps(),
8585
slots: ['upHandler', 'downHandler'],
8686
setup(props, { attrs, slots, emit, expose }) {
8787
const inputRef = ref<HTMLInputElement>();

components/input/Input.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ export function triggerFocus(
107107
export default defineComponent({
108108
name: 'AInput',
109109
inheritAttrs: false,
110-
props: {
111-
...inputProps,
112-
},
110+
props: inputProps(),
113111
setup(props, { slots, attrs, expose, emit }) {
114112
const inputRef = ref();
115113
const clearableInputRef = ref();

components/input/Password.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default defineComponent({
2323
mixins: [BaseMixin],
2424
inheritAttrs: false,
2525
props: {
26-
...inputProps,
26+
...inputProps(),
2727
prefixCls: String,
2828
inputPrefixCls: String,
2929
action: PropTypes.string.def('click'),

components/input/ResizableTextArea.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const ResizableTextArea = defineComponent({
2727
name: 'ResizableTextArea',
2828
mixins: [BaseMixin],
2929
inheritAttrs: false,
30-
props: textAreaProps,
30+
props: textAreaProps(),
3131
setup(props, { attrs, emit, expose }) {
3232
let nextFrameActionId: any;
3333
let resizeFrameId: any;

components/input/Search.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default defineComponent({
1717
name: 'AInputSearch',
1818
inheritAttrs: false,
1919
props: {
20-
...inputProps,
20+
...inputProps(),
2121
inputPrefixCls: String,
2222
// 不能设置默认值 https://github.com/vueComponent/ant-design-vue/issues/1916
2323
enterButton: PropTypes.any,

components/input/TextArea.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function setTriggerValue(
4747
export default defineComponent({
4848
name: 'ATextarea',
4949
inheritAttrs: false,
50-
props: textAreaProps,
50+
props: textAreaProps(),
5151
setup(props, { attrs, expose, emit }) {
5252
const formItemContext = useInjectFormItemContext();
5353
const stateValue = ref(props.value === undefined ? props.defaultValue : props.value);

components/input/inputProps.ts

+23-17
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ import PropTypes from '../_util/vue-types';
33
import type { SizeType } from '../config-provider';
44
import omit from '../_util/omit';
55
import type { LiteralUnion, VueNode } from '../_util/type';
6+
import type {
7+
ChangeEventHandler,
8+
CompositionEventHandler,
9+
FocusEventHandler,
10+
KeyboardEventHandler,
11+
} from '../_util/EventInterface';
612
export const inputDefaultValue = Symbol() as unknown as string;
7-
const inputProps = {
13+
const inputProps = () => ({
814
id: String,
915
prefixCls: String,
1016
inputPrefixCls: String,
@@ -63,19 +69,19 @@ const inputProps = {
6369
bordered: { type: Boolean, default: undefined },
6470
showCount: { type: [Boolean, Object] as PropType<boolean | ShowCountProps> },
6571
htmlSize: Number,
66-
onPressEnter: Function,
67-
onKeydown: Function,
68-
onKeyup: Function,
69-
onFocus: Function,
70-
onBlur: Function,
71-
onChange: Function,
72-
onInput: Function,
73-
'onUpdate:value': Function,
72+
onPressEnter: Function as PropType<KeyboardEventHandler>,
73+
onKeydown: Function as PropType<KeyboardEventHandler>,
74+
onKeyup: Function as PropType<KeyboardEventHandler>,
75+
onFocus: Function as PropType<FocusEventHandler>,
76+
onBlur: Function as PropType<FocusEventHandler>,
77+
onChange: Function as PropType<ChangeEventHandler>,
78+
onInput: Function as PropType<ChangeEventHandler>,
79+
'onUpdate:value': Function as PropType<(val: string) => void>,
7480
valueModifiers: Object,
7581
hidden: Boolean,
76-
};
82+
});
7783
export default inputProps;
78-
export type InputProps = Partial<ExtractPropTypes<typeof inputProps>>;
84+
export type InputProps = Partial<ExtractPropTypes<ReturnType<typeof inputProps>>>;
7985

8086
export interface AutoSizeType {
8187
minRows?: number;
@@ -84,17 +90,17 @@ export interface AutoSizeType {
8490
export interface ShowCountProps {
8591
formatter: (args: { count: number; maxlength?: number }) => VueNode;
8692
}
87-
const textAreaProps = {
88-
...omit(inputProps, ['prefix', 'addonBefore', 'addonAfter', 'suffix']),
93+
const textAreaProps = () => ({
94+
...omit(inputProps(), ['prefix', 'addonBefore', 'addonAfter', 'suffix']),
8995
rows: Number,
9096
autosize: { type: [Boolean, Object] as PropType<AutoSizeType>, default: undefined },
9197
autoSize: { type: [Boolean, Object] as PropType<AutoSizeType>, default: undefined },
9298
onResize: { type: Function as PropType<(size: { width: number; height: number }) => void> },
93-
onCompositionstart: Function,
94-
onCompositionend: Function,
99+
onCompositionstart: Function as PropType<CompositionEventHandler>,
100+
onCompositionend: Function as PropType<CompositionEventHandler>,
95101
valueModifiers: Object,
96-
};
102+
});
97103

98104
export { textAreaProps };
99105

100-
export type TextAreaProps = Partial<ExtractPropTypes<typeof textAreaProps>>;
106+
export type TextAreaProps = Partial<ExtractPropTypes<ReturnType<typeof textAreaProps>>>;

0 commit comments

Comments
 (0)