Skip to content

Commit 00dc2ad

Browse files
authored
chore: update ts type (#5408)
* feat: update prop type * feat: update ts type * feat: update ts type * feat: update ts type * feat: update ts type * test: update snap * feat: update ts type
1 parent 790f83f commit 00dc2ad

File tree

165 files changed

+1550
-1353
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+1550
-1353
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/_util/Portal.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default defineComponent({
1515
inheritAttrs: false,
1616
props: {
1717
getContainer: PropTypes.func.isRequired,
18-
didUpdate: PropTypes.func,
18+
didUpdate: Function,
1919
},
2020
setup(props, { slots }) {
2121
let isSSR = true;

components/_util/PortalWrapper.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ export default defineComponent({
5252
name: 'PortalWrapper',
5353
inheritAttrs: false,
5454
props: {
55-
wrapperClassName: PropTypes.string,
56-
forceRender: PropTypes.looseBool,
55+
wrapperClassName: String,
56+
forceRender: { type: Boolean, default: undefined },
5757
getContainer: PropTypes.any,
58-
visible: PropTypes.looseBool,
58+
visible: { type: Boolean, default: undefined },
5959
},
6060

6161
setup(props, { slots }) {

components/_util/transButton.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { defineComponent, ref, onMounted } from 'vue';
55
* This helps accessibility reader to tread as a interactive button to operation.
66
*/
77
import KeyCode from './KeyCode';
8-
import PropTypes from './vue-types';
98

109
const inlineStyle = {
1110
border: 0,
@@ -19,10 +18,10 @@ const TransButton = defineComponent({
1918
name: 'TransButton',
2019
inheritAttrs: false,
2120
props: {
22-
noStyle: PropTypes.looseBool,
23-
onClick: PropTypes.func,
24-
disabled: PropTypes.looseBool,
25-
autofocus: PropTypes.looseBool,
21+
noStyle: { type: Boolean, default: undefined },
22+
onClick: Function,
23+
disabled: { type: Boolean, default: undefined },
24+
autofocus: { type: Boolean, default: undefined },
2625
},
2726
setup(props, { slots, emit, attrs, expose }) {
2827
const domRef = ref();

components/affix/index.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,22 @@ export const affixProps = () => ({
4747
offsetTop: Number,
4848
/** 距离窗口底部达到指定偏移量后触发 */
4949
offsetBottom: Number,
50-
/** 固定状态改变时触发的回调函数 */
51-
// onChange?: (affixed?: boolean) => void;
5250
/** 设置 Affix 需要监听其滚动事件的元素,值为一个返回对应 DOM 元素的函数 */
5351
target: {
5452
type: Function as PropType<() => Window | HTMLElement | null>,
5553
default: getDefaultTarget,
5654
},
5755
prefixCls: String,
56+
/** 固定状态改变时触发的回调函数 */
5857
onChange: Function as PropType<AffixEmits['change']>,
5958
onTestUpdatePosition: Function as PropType<AffixEmits['testUpdatePosition']>,
6059
});
6160

6261
export type AffixProps = Partial<ExtractPropTypes<ReturnType<typeof affixProps>>>;
6362

6463
export type AffixEmits = {
65-
change: (lastAffix: boolean) => boolean;
66-
testUpdatePosition: () => boolean;
64+
change: (lastAffix: boolean) => void;
65+
testUpdatePosition: () => void;
6766
};
6867

6968
export type AffixExpose = {

components/alert/index.tsx

+5-7
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import { cloneElement } from '../_util/vnode';
1818
import type { NodeMouseEventHandler } from '../vc-tree/contextTypes';
1919
import useConfigInject from '../_util/hooks/useConfigInject';
2020

21-
function noop() {}
22-
2321
const iconMapFilled = {
2422
success: CheckCircleFilled,
2523
info: InfoCircleFilled,
@@ -44,19 +42,19 @@ export const alertProps = () => ({
4442
*/
4543
type: PropTypes.oneOf(AlertTypes),
4644
/** Whether Alert can be closed */
47-
closable: PropTypes.looseBool,
45+
closable: { type: Boolean, default: undefined },
4846
/** Close text to show */
4947
closeText: PropTypes.any,
5048
/** Content of Alert */
5149
message: PropTypes.any,
5250
/** Additional content of Alert */
5351
description: PropTypes.any,
5452
/** Trigger when animation ending of Alert */
55-
afterClose: PropTypes.func.def(noop),
53+
afterClose: Function as PropType<() => void>,
5654
/** Whether to show icon */
57-
showIcon: PropTypes.looseBool,
58-
prefixCls: PropTypes.string,
59-
banner: PropTypes.looseBool,
55+
showIcon: { type: Boolean, default: undefined },
56+
prefixCls: String,
57+
banner: { type: Boolean, default: undefined },
6058
icon: PropTypes.any,
6159
closeIcon: PropTypes.any,
6260
onClose: Function as PropType<NodeMouseEventHandler>,

components/anchor/AnchorLink.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import type { ExtractPropTypes } from 'vue';
22
import { defineComponent, nextTick, onBeforeUnmount, onMounted, watch } from 'vue';
33
import PropTypes from '../_util/vue-types';
4-
import { getPropsSlot } from '../_util/props-util';
4+
import { getPropsSlot, initDefaultProps } from '../_util/props-util';
55
import classNames from '../_util/classNames';
66
import useConfigInject from '../_util/hooks/useConfigInject';
77
import { useInjectAnchor } from './context';
88

9-
export const anchorLinkProps = {
10-
prefixCls: PropTypes.string,
11-
href: PropTypes.string.def('#'),
9+
export const anchorLinkProps = () => ({
10+
prefixCls: String,
11+
href: String,
1212
title: PropTypes.any,
13-
target: PropTypes.string,
14-
};
13+
target: String,
14+
});
1515

16-
export type AnchorLinkProps = Partial<ExtractPropTypes<typeof anchorLinkProps>>;
16+
export type AnchorLinkProps = Partial<ExtractPropTypes<ReturnType<typeof anchorLinkProps>>>;
1717

1818
export default defineComponent({
1919
name: 'AAnchorLink',
20-
props: anchorLinkProps,
20+
props: initDefaultProps(anchorLinkProps(), { href: '#' }),
2121
slots: ['title'],
2222
setup(props, { slots }) {
2323
let mergedTitle = null;

components/anchor/demo/onClick.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ Clicking on an anchor does not record history.
2828

2929
<script lang="ts">
3030
import { defineComponent } from 'vue';
31+
import type { AnchorProps } from 'ant-design-vue';
3132
3233
export default defineComponent({
3334
setup() {
34-
const handleClick = (e: Event, link: string) => {
35+
const handleClick: AnchorProps['onClick'] = (e, link) => {
3536
e.preventDefault();
3637
console.log(link);
3738
};

components/auto-complete/index.tsx

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import type { App, VNode, ExtractPropTypes } from 'vue';
1+
import type { App, VNode, ExtractPropTypes, CSSProperties, PropType } from 'vue';
22
import { defineComponent, ref } from 'vue';
33
import Select, { selectProps } from '../select';
4-
import PropTypes from '../_util/vue-types';
54
import { isValidElement, flattenChildren } from '../_util/props-util';
65
import warning from '../_util/warning';
76
import Option from './Option';
@@ -13,15 +12,27 @@ function isSelectOptionOrSelectOptGroup(child: any): boolean {
1312
return child?.type?.isSelectOption || child?.type?.isSelectOptGroup;
1413
}
1514

16-
export const autoCompleteProps = {
15+
export const autoCompleteProps = () => ({
1716
...omit(selectProps(), ['loading', 'mode', 'optionLabelProp', 'labelInValue']),
18-
dataSource: PropTypes.array,
19-
dropdownMenuStyle: PropTypes.style,
20-
// optionLabelProp: PropTypes.string,
17+
dataSource: Array as PropType<{ value: any; text: any }[] | string[]>,
18+
dropdownMenuStyle: {
19+
type: Object as PropType<CSSProperties>,
20+
default: undefined as CSSProperties,
21+
},
22+
// optionLabelProp: String,
2123
dropdownMatchSelectWidth: { type: [Number, Boolean], default: true },
22-
};
24+
prefixCls: String,
25+
showSearch: { type: Boolean, default: undefined },
26+
transitionName: String,
27+
choiceTransitionName: { type: String, default: 'zoom' },
28+
autofocus: { type: Boolean, default: undefined },
29+
backfill: { type: Boolean, default: undefined },
30+
// optionLabelProp: PropTypes.string.def('children'),
31+
filterOption: { type: [Boolean, Function], default: false },
32+
defaultActiveFirstOption: { type: Boolean, default: true },
33+
});
2334

24-
export type AutoCompleteProps = Partial<ExtractPropTypes<typeof autoCompleteProps>>;
35+
export type AutoCompleteProps = Partial<ExtractPropTypes<ReturnType<typeof autoCompleteProps>>>;
2536

2637
export const AutoCompleteOption = Option;
2738

@@ -30,19 +41,8 @@ export const AutoCompleteOptGroup = OptGroup;
3041
const AutoComplete = defineComponent({
3142
name: 'AAutoComplete',
3243
inheritAttrs: false,
33-
props: {
34-
...autoCompleteProps,
35-
prefixCls: PropTypes.string,
36-
showSearch: PropTypes.looseBool,
37-
transitionName: PropTypes.string,
38-
choiceTransitionName: PropTypes.string.def('zoom'),
39-
autofocus: PropTypes.looseBool,
40-
backfill: PropTypes.looseBool,
41-
// optionLabelProp: PropTypes.string.def('children'),
42-
filterOption: PropTypes.oneOfType([PropTypes.looseBool, PropTypes.func]).def(false),
43-
defaultActiveFirstOption: PropTypes.looseBool.def(true),
44-
},
45-
emits: ['change', 'select', 'focus', 'blur'],
44+
props: autoCompleteProps(),
45+
// emits: ['change', 'select', 'focus', 'blur'],
4646
slots: ['option'],
4747
setup(props, { slots, attrs, expose }) {
4848
warning(

components/avatar/Avatar.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { VueNode } from '../_util/type';
2-
import { tuple } from '../_util/type';
2+
33
import type { CSSProperties, ExtractPropTypes, PropType } from 'vue';
44
import { computed, defineComponent, nextTick, onMounted, ref, watch } from 'vue';
55
import { getPropsSlot } from '../_util/props-util';
@@ -15,19 +15,19 @@ import eagerComputed from '../_util/eagerComputed';
1515
export type AvatarSize = 'large' | 'small' | 'default' | number | ScreenSizeMap;
1616

1717
export const avatarProps = () => ({
18-
prefixCls: PropTypes.string,
19-
shape: PropTypes.oneOf(tuple('circle', 'square')).def('circle'),
18+
prefixCls: String,
19+
shape: { type: String as PropType<'circle' | 'square'>, default: 'circle' },
2020
size: {
2121
type: [Number, String, Object] as PropType<AvatarSize>,
2222
default: (): AvatarSize => 'default',
2323
},
24-
src: PropTypes.string,
24+
src: String,
2525
/** Srcset of image avatar */
26-
srcset: PropTypes.string,
26+
srcset: String,
2727
icon: PropTypes.any,
28-
alt: PropTypes.string,
29-
gap: PropTypes.number,
30-
draggable: PropTypes.bool,
28+
alt: String,
29+
gap: Number,
30+
draggable: { type: Boolean, default: undefined },
3131
crossOrigin: String as PropType<'' | 'anonymous' | 'use-credentials'>,
3232
loadError: {
3333
type: Function as PropType<() => boolean>,

components/avatar/Group.tsx

+5-10
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,23 @@ import Avatar from './Avatar';
44
import Popover from '../popover';
55
import type { PropType, ExtractPropTypes, CSSProperties } from 'vue';
66
import { defineComponent } from 'vue';
7-
import PropTypes from '../_util/vue-types';
87
import { flattenChildren, getPropsSlot } from '../_util/props-util';
9-
import { tuple } from '../_util/type';
108
import useConfigInject from '../_util/hooks/useConfigInject';
119
import useProvideSize from '../_util/hooks/useSize';
1210

1311
export const groupProps = () => ({
14-
prefixCls: PropTypes.string,
15-
maxCount: PropTypes.number,
16-
maxStyle: {
17-
type: Object as PropType<CSSProperties>,
18-
default: () => ({} as CSSProperties),
19-
},
20-
maxPopoverPlacement: PropTypes.oneOf(tuple('top', 'bottom')).def('top'),
12+
prefixCls: String,
13+
maxCount: Number,
14+
maxStyle: { type: Object as PropType<CSSProperties>, default: undefined as CSSProperties },
15+
maxPopoverPlacement: { type: String as PropType<'top' | 'bottom'>, default: 'top' },
2116
maxPopoverTrigger: String as PropType<'hover' | 'focus' | 'click'>,
2217
/*
2318
* Size of avatar, options: `large`, `small`, `default`
2419
* or a custom number size
2520
* */
2621
size: {
2722
type: [Number, String, Object] as PropType<AvatarSize>,
28-
default: (): AvatarSize => 'default',
23+
default: 'default' as AvatarSize,
2924
},
3025
});
3126

components/avatar/__tests__/__snapshots__/Avatar.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ exports[`Avatar Render adjusts component size to 80 when window size is xl 1`] =
1212

1313
exports[`Avatar Render adjusts component size to 100 when window size is xxl 1`] = `<span class="ant-avatar ant-avatar-circle" style="width: 100px; height: 100px; line-height: 100px; font-size: 18px;"><span class="ant-avatar-string" style="transform: scale(0.32) translateX(-50%);"><!----></span></span>`;
1414

15-
exports[`Avatar Render fallback 1`] = `<span class="ant-avatar ant-avatar-circle ant-avatar-image"><img draggable="false" src="http://error.url"></span>`;
15+
exports[`Avatar Render fallback 1`] = `<span class="ant-avatar ant-avatar-circle ant-avatar-image"><img src="http://error.url"></span>`;
1616
1717
exports[`Avatar Render should calculate scale of avatar children correctly 1`] = `<span class="ant-avatar-string" style="transform: scale(0.72) translateX(-50%);">Avatar</span>`;
1818

0 commit comments

Comments
 (0)