Skip to content

Commit 4ab7a68

Browse files
authored
fix: declare components type (#3145)
* fix: update alert code * chore: declare link type * chore: declare auto-complete type * chore: declare Badge type * chore: declare Breadcrumb type * chore: declare Calendar type * chore: declare Card type * chore: declare Checkbox type * chore: declare Descriptions type * chore: declare Dropdown * chore: declare Form type * chore: declare Mentions type * chore: declare Menu type * chore: declare popconfirm type * chore: update Radio typescript * chore: declare Rate type * chore: declare Transfer type * fix: update Transfer type * fix: update type * fix: update type
1 parent ba971c4 commit 4ab7a68

File tree

22 files changed

+101
-90
lines changed

22 files changed

+101
-90
lines changed

components/alert/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const iconMapOutlined = {
3434

3535
export const AlertProps = {
3636
/**
37-
* Type of Alert styles, options:`success`, `info`, `warning`, `error`
37+
* Type of Alert styles, options: `success`, `info`, `warning`, `error`
3838
*/
3939
type: PropTypes.oneOf(tuple('success', 'info', 'warning', 'error')),
4040
/** Whether Alert can be closed */

components/anchor/Anchor.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export default defineComponent({
183183
return '';
184184
},
185185

186-
handleScrollTo(link) {
186+
handleScrollTo(link: string) {
187187
const { offsetTop, getContainer, targetOffset } = this;
188188

189189
this.setCurrentActiveLink(link);

components/auto-complete/index.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App, defineComponent, inject, provide, Plugin } from 'vue';
1+
import { App, defineComponent, inject, provide, Plugin, VNode } from 'vue';
22
import Select, { SelectProps } from '../select';
33
import Input from '../input';
44
import InputElement from './InputElement';
@@ -56,10 +56,10 @@ const AutoComplete = defineComponent({
5656
provide('savePopupRef', this.savePopupRef);
5757
},
5858
methods: {
59-
savePopupRef(ref: any) {
59+
savePopupRef(ref: VNode) {
6060
this.popupRef = ref;
6161
},
62-
saveSelect(node: any) {
62+
saveSelect(node: VNode) {
6363
this.select = node;
6464
},
6565
getInputElement() {
@@ -125,7 +125,7 @@ const AutoComplete = defineComponent({
125125
: [];
126126
}
127127
const selectProps = {
128-
...Omit(getOptionProps(this), ['dataSource', 'optionLabelProp'] as any),
128+
...Omit(getOptionProps(this), ['dataSource', 'optionLabelProp']),
129129
...this.$attrs,
130130
mode: Select.SECRET_COMBOBOX_MODE_DO_NOT_USE,
131131
// optionLabelProp,

components/badge/Badge.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { cloneElement } from '../_util/vnode';
77
import { getTransitionProps, Transition } from '../_util/transition';
88
import isNumeric from '../_util/isNumeric';
99
import { defaultConfigProvider } from '../config-provider';
10-
import { inject, defineComponent, CSSProperties } from 'vue';
10+
import { inject, defineComponent, CSSProperties, VNode } from 'vue';
1111
import { tuple } from '../_util/type';
1212

1313
const BadgeProps = {
@@ -28,7 +28,7 @@ const BadgeProps = {
2828
title: PropTypes.string,
2929
};
3030
function isPresetColor(color?: string): boolean {
31-
return (PresetColorTypes as any[]).indexOf(color) !== -1;
31+
return (PresetColorTypes as string[]).indexOf(color) !== -1;
3232
}
3333
export default defineComponent({
3434
name: 'ABadge',
@@ -79,7 +79,7 @@ export default defineComponent({
7979
}
8080
: { ...numberStyle };
8181
},
82-
getBadgeClassName(prefixCls: string, children: any[]) {
82+
getBadgeClassName(prefixCls: string, children: VNode[]) {
8383
const hasStatus = this.hasStatus();
8484
return classNames(prefixCls, {
8585
[`${prefixCls}-status`]: hasStatus,

components/breadcrumb/Breadcrumb.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ const BreadcrumbProps = {
2020
separator: PropTypes.VNodeChild,
2121
itemRender: {
2222
type: Function as PropType<
23-
(opt: { route: Route; params: any; routes: Route[]; paths: string[] }) => VueNode
23+
(opt: { route: Route; params: unknown; routes: Route[]; paths: string[] }) => VueNode
2424
>,
2525
},
2626
};
2727

28-
function getBreadcrumbName(route: Route, params: any) {
28+
function getBreadcrumbName(route: Route, params: unknown) {
2929
if (!route.breadcrumbName) {
3030
return null;
3131
}
@@ -38,7 +38,7 @@ function getBreadcrumbName(route: Route, params: any) {
3838
}
3939
function defaultItemRender(opt: {
4040
route: Route;
41-
params: any;
41+
params: unknown;
4242
routes: Route[];
4343
paths: string[];
4444
}): VueNode {
@@ -57,15 +57,15 @@ export default defineComponent({
5757
};
5858
},
5959
methods: {
60-
getPath(path: string, params: any) {
60+
getPath(path: string, params: unknown) {
6161
path = (path || '').replace(/^\//, '');
6262
Object.keys(params).forEach(key => {
6363
path = path.replace(`:${key}`, params[key]);
6464
});
6565
return path;
6666
},
6767

68-
addChildPath(paths: string[], childPath = '', params: any) {
68+
addChildPath(paths: string[], childPath = '', params: unknown) {
6969
const originalPaths = [...paths];
7070
const path = this.getPath(childPath, params);
7171
if (path) {

components/breadcrumb/BreadcrumbItem.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineComponent, inject } from 'vue';
1+
import { defineComponent, HTMLAttributes, inject } from 'vue';
22
import PropTypes from '../_util/vue-types';
33
import { hasProp, getComponent, getSlot } from '../_util/props-util';
44
import { defaultConfigProvider } from '../config-provider';
@@ -24,7 +24,7 @@ export default defineComponent({
2424
* if overlay is have
2525
* Wrap a DropDown
2626
*/
27-
renderBreadcrumbNode(breadcrumbItem: any, prefixCls: string) {
27+
renderBreadcrumbNode(breadcrumbItem: HTMLAttributes, prefixCls: string) {
2828
const overlay = getComponent(this, 'overlay');
2929
if (overlay) {
3030
return (
@@ -45,7 +45,7 @@ export default defineComponent({
4545
const prefixCls = getPrefixCls('breadcrumb', customizePrefixCls);
4646
const separator = getComponent(this, 'separator');
4747
const children = getSlot(this);
48-
let link;
48+
let link: HTMLAttributes;
4949
if (hasProp(this, 'href')) {
5050
link = <a class={`${prefixCls}-link`}>{children}</a>;
5151
} else {

components/calendar/Header.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import PropTypes from '../_util/vue-types';
55
import { defaultConfigProvider } from '../config-provider';
66
import { VueNode } from '../_util/type';
77
import moment from 'moment';
8+
import { RadioChangeEvent } from '../radio/interface';
89

910
function getMonthsLocale(value: moment.Moment): string[] {
1011
const current = value.clone();
@@ -141,8 +142,8 @@ export default defineComponent({
141142
this.$emit('valueChange', newValue);
142143
},
143144

144-
onInternalTypeChange(e: Event) {
145-
this.triggerTypeChange((e.target as any).value);
145+
onInternalTypeChange(e: RadioChangeEvent) {
146+
this.triggerTypeChange(e.target.value);
146147
},
147148

148149
triggerTypeChange(val: string) {

components/card/Card.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const Card = defineComponent({
7171
this.$emit('tabChange', key);
7272
},
7373
isContainGrid(obj: VNode[] = []) {
74-
let containGrid;
74+
let containGrid: boolean;
7575
obj.forEach(element => {
7676
if (element && isPlainObject(element.type) && (element.type as any).__ANT_CARD_GRID) {
7777
containGrid = true;

components/checkbox/Checkbox.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import VcCheckbox from '../vc-checkbox';
55
import hasProp, { getOptionProps, getSlot } from '../_util/props-util';
66
import { defaultConfigProvider } from '../config-provider';
77
import warning from '../_util/warning';
8+
import { RadioChangeEvent } from '../radio/interface';
89
function noop() {}
910

1011
export default defineComponent({
@@ -65,17 +66,17 @@ export default defineComponent({
6566
}
6667
},
6768
methods: {
68-
handleChange(event: Event) {
69-
const targetChecked = (event.target as any).checked;
69+
handleChange(event: RadioChangeEvent) {
70+
const targetChecked = event.target.checked;
7071
this.$emit('update:checked', targetChecked);
7172
// this.$emit('input', targetChecked);
7273
this.$emit('change', event);
7374
},
7475
focus() {
75-
(this.$refs.vcCheckbox as any).focus();
76+
(this.$refs.vcCheckbox as HTMLInputElement).focus();
7677
},
7778
blur() {
78-
(this.$refs.vcCheckbox as any).blur();
79+
(this.$refs.vcCheckbox as HTMLInputElement).blur();
7980
},
8081
},
8182

@@ -93,7 +94,7 @@ export default defineComponent({
9394
class: className,
9495
style,
9596
...restAttrs
96-
} = $attrs as any;
97+
} = $attrs;
9798
const checkboxProps: any = {
9899
...restProps,
99100
prefixCls,

components/descriptions/Row.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Cell from './Cell';
22
import { getOptionProps, getSlot, getClass, getStyle, getComponent } from '../_util/props-util';
3-
import { FunctionalComponent } from 'vue';
3+
import { FunctionalComponent, VNode } from 'vue';
44

55
interface CellConfig {
66
component: string | [string, string];
@@ -20,7 +20,7 @@ export interface RowProps {
2020

2121
const Row: FunctionalComponent<RowProps> = props => {
2222
const renderCells = (
23-
items,
23+
items: VNode[],
2424
{ colon, prefixCls, bordered },
2525
{ component, type, showLabel, showContent }: CellConfig,
2626
) => {

components/dropdown/dropdown-button.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { provide, inject, defineComponent } from 'vue';
1+
import { provide, inject, defineComponent, VNode } from 'vue';
22
import Button from '../button';
33
import classNames from '../_util/classNames';
44
import buttonTypes from '../button/buttonTypes';
@@ -45,13 +45,13 @@ export default defineComponent({
4545
provide('savePopupRef', this.savePopupRef);
4646
},
4747
methods: {
48-
savePopupRef(ref: any) {
48+
savePopupRef(ref: VNode) {
4949
this.popupRef = ref;
5050
},
51-
handleClick(e) {
51+
handleClick(e: Event) {
5252
this.$emit('click', e);
5353
},
54-
handleVisibleChange(val) {
54+
handleVisibleChange(val: boolean) {
5555
this.$emit('update:visible', val);
5656
this.$emit('visibleChange', val);
5757
},

components/dropdown/dropdown.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { provide, inject, cloneVNode, defineComponent } from 'vue';
1+
import { provide, inject, cloneVNode, defineComponent, VNode } from 'vue';
22
import RcDropdown from '../vc-dropdown/src/index';
33
import DropdownButton from './dropdown-button';
44
import PropTypes from '../_util/vue-types';
@@ -37,7 +37,7 @@ const Dropdown = defineComponent({
3737
provide('savePopupRef', this.savePopupRef);
3838
},
3939
methods: {
40-
savePopupRef(ref: any) {
40+
savePopupRef(ref: VNode) {
4141
this.popupRef = ref;
4242
},
4343
getTransitionName() {

components/form/Form.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import scrollIntoView from 'scroll-into-view-if-needed';
1414
import initDefaultProps from '../_util/props-util/initDefaultProps';
1515
import { tuple, VueNode } from '../_util/type';
1616
import { ColProps } from '../grid/Col';
17-
import { InternalNamePath, NamePath, ValidateOptions } from './interface';
17+
import { InternalNamePath, NamePath, ValidateErrorEntity, ValidateOptions } from './interface';
1818

1919
export type ValidationRule = {
2020
/** validation error message */
@@ -119,7 +119,7 @@ const Form = defineComponent({
119119
this.handleFinishFailed(errors);
120120
});
121121
},
122-
getFieldsByNameList(nameList) {
122+
getFieldsByNameList(nameList: NamePath) {
123123
const provideNameList = !!nameList;
124124
const namePathList = provideNameList ? toArray(nameList).map(getNamePath) : [];
125125
if (!provideNameList) {
@@ -139,12 +139,12 @@ const Form = defineComponent({
139139
field.resetField();
140140
});
141141
},
142-
clearValidate(name) {
142+
clearValidate(name: NamePath) {
143143
this.getFieldsByNameList(name).forEach(field => {
144144
field.clearValidate();
145145
});
146146
},
147-
handleFinishFailed(errorInfo) {
147+
handleFinishFailed(errorInfo: ValidateErrorEntity) {
148148
const { scrollToFirstError } = this;
149149
this.$emit('finishFailed', errorInfo);
150150
if (scrollToFirstError && errorInfo.errorFields.length) {
@@ -154,8 +154,8 @@ const Form = defineComponent({
154154
validate(...args: any[]) {
155155
return this.validateField(...args);
156156
},
157-
scrollToField(name: string | number, options = {}) {
158-
const fields = this.getFieldsByNameList([name]);
157+
scrollToField(name: NamePath, options = {}) {
158+
const fields = this.getFieldsByNameList(name);
159159
if (fields.length) {
160160
const fieldId = fields[0].fieldId;
161161
const node = fieldId ? document.getElementById(fieldId) : null;

components/mentions/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ const Mentions = defineComponent({
151151
return filterOption;
152152
},
153153
focus() {
154-
(this.$refs.vcMentions as any).focus();
154+
(this.$refs.vcMentions as HTMLTextAreaElement).focus();
155155
},
156156
blur() {
157-
(this.$refs.vcMentions as any).blur();
157+
(this.$refs.vcMentions as HTMLTextAreaElement).blur();
158158
},
159159
},
160160
render() {

components/menu/SubMenu.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default defineComponent({
2424
};
2525
},
2626
methods: {
27-
onKeyDown(e) {
27+
onKeyDown(e: Event) {
2828
(this.$refs.subMenu as any).onKeyDown(e);
2929
},
3030
},

0 commit comments

Comments
 (0)