Skip to content

Commit b1b9b53

Browse files
committed
feat: update ts type
1 parent 1a7c41b commit b1b9b53

File tree

15 files changed

+111
-110
lines changed

15 files changed

+111
-110
lines changed

components/alert/index.tsx

+1-3
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,
@@ -52,7 +50,7 @@ export const alertProps = () => ({
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 */
5755
showIcon: { type: Boolean, default: undefined },
5856
prefixCls: String,

components/anchor/AnchorLink.tsx

+6-6
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 = {
9+
export const anchorLinkProps = () => ({
1010
prefixCls: String,
11-
href: PropTypes.string.def('#'),
11+
href: String,
1212
title: PropTypes.any,
1313
target: String,
14-
};
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/auto-complete/index.tsx

+20-20
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,
17+
dataSource: Array as PropType<{ value: any; text: any }[] | string[]>,
18+
dropdownMenuStyle: {
19+
type: Object as PropType<CSSProperties>,
20+
default: undefined as CSSProperties,
21+
},
2022
// 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: String,
36-
showSearch: { type: Boolean, default: undefined },
37-
transitionName: String,
38-
choiceTransitionName: PropTypes.string.def('zoom'),
39-
autofocus: { type: Boolean, default: undefined },
40-
backfill: { type: Boolean, default: undefined },
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

+3-3
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';
@@ -16,7 +16,7 @@ export type AvatarSize = 'large' | 'small' | 'default' | number | ScreenSizeMap;
1616

1717
export const avatarProps = () => ({
1818
prefixCls: String,
19-
shape: PropTypes.oneOf(tuple('circle', 'square')).def('circle'),
19+
shape: { type: String as PropType<'circle' | 'square'>, default: 'circle' },
2020
size: {
2121
type: [Number, String, Object] as PropType<AvatarSize>,
2222
default: (): AvatarSize => 'default',
@@ -27,7 +27,7 @@ export const avatarProps = () => ({
2727
icon: PropTypes.any,
2828
alt: String,
2929
gap: Number,
30-
draggable: PropTypes.bool,
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

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ 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

@@ -15,17 +13,17 @@ export const groupProps = () => ({
1513
maxCount: Number,
1614
maxStyle: {
1715
type: Object as PropType<CSSProperties>,
18-
default: () => ({} as CSSProperties),
16+
default: undefined as CSSProperties,
1917
},
20-
maxPopoverPlacement: PropTypes.oneOf(tuple('top', 'bottom')).def('top'),
18+
maxPopoverPlacement: { type: String as PropType<'top' | 'bottom'>, default: 'top' },
2119
maxPopoverTrigger: String as PropType<'hover' | 'focus' | 'click'>,
2220
/*
2321
* Size of avatar, options: `large`, `small`, `default`
2422
* or a custom number size
2523
* */
2624
size: {
2725
type: [Number, String, Object] as PropType<AvatarSize>,
28-
default: (): AvatarSize => 'default',
26+
default: 'default' as AvatarSize,
2927
},
3028
});
3129

components/back-top/index.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,31 @@ import {
1111
onDeactivated,
1212
} from 'vue';
1313
import VerticalAlignTopOutlined from '@ant-design/icons-vue/VerticalAlignTopOutlined';
14-
import PropTypes from '../_util/vue-types';
1514
import addEventListener from '../vc-util/Dom/addEventListener';
1615
import getScroll from '../_util/getScroll';
1716
import { getTransitionProps, Transition } from '../_util/transition';
1817
import scrollTo from '../_util/scrollTo';
1918
import { withInstall } from '../_util/type';
2019
import throttleByAnimationFrame from '../_util/throttleByAnimationFrame';
2120
import useConfigInject from '../_util/hooks/useConfigInject';
21+
import type { MouseEventHandler } from '../_util/EventInterface';
2222

23-
export const backTopProps = {
24-
visibilityHeight: PropTypes.number.def(400),
25-
duration: PropTypes.number.def(450),
23+
export const backTopProps = () => ({
24+
visibilityHeight: { type: Number, default: 400 },
25+
duration: { type: Number, default: 450 },
2626
target: Function as PropType<() => HTMLElement | Window | Document>,
2727
prefixCls: String,
28-
onClick: Function,
28+
onClick: Function as PropType<MouseEventHandler>,
2929
// visible: { type: Boolean, default: undefined }, // Only for test. Don't use it.
30-
};
30+
});
3131

3232
export type BackTopProps = Partial<ExtractPropTypes<typeof backTopProps>>;
3333

3434
const BackTop = defineComponent({
3535
name: 'ABackTop',
3636
inheritAttrs: false,
37-
props: backTopProps,
38-
emits: ['click'],
37+
props: backTopProps(),
38+
// emits: ['click'],
3939
setup(props, { slots, attrs, emit }) {
4040
const { prefixCls, direction } = useConfigInject('back-top', props);
4141
const domRef = ref();

components/badge/Badge.tsx

+12-13
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,40 @@ import classNames from '../_util/classNames';
44
import { getPropsSlot, flattenChildren } from '../_util/props-util';
55
import { cloneElement } from '../_util/vnode';
66
import { getTransitionProps, Transition } from '../_util/transition';
7-
import type { ExtractPropTypes, CSSProperties } from 'vue';
7+
import type { ExtractPropTypes, CSSProperties, PropType } from 'vue';
88
import { defineComponent, computed, ref, watch } from 'vue';
9-
import { tuple } from '../_util/type';
109
import Ribbon from './Ribbon';
1110
import { isPresetColor } from './utils';
1211
import useConfigInject from '../_util/hooks/useConfigInject';
1312
import isNumeric from '../_util/isNumeric';
13+
import type { PresetStatusColorType } from '../_util/colors';
1414

15-
export const badgeProps = {
15+
export const badgeProps = () => ({
1616
/** Number to show in badge */
1717
count: PropTypes.any,
1818
showZero: { type: Boolean, default: undefined },
1919
/** Max count to show */
20-
overflowCount: PropTypes.number.def(99),
20+
overflowCount: { type: Number, default: 99 },
2121
/** whether to show red dot without number */
2222
dot: { type: Boolean, default: undefined },
2323
prefixCls: String,
2424
scrollNumberPrefixCls: String,
25-
status: PropTypes.oneOf(tuple('success', 'processing', 'default', 'error', 'warning')),
26-
27-
size: PropTypes.oneOf(tuple('default', 'small')).def('default'),
25+
status: { type: String as PropType<PresetStatusColorType> },
26+
size: { type: String as PropType<'default' | 'small'>, default: 'default' },
2827
color: String,
2928
text: PropTypes.any,
30-
offset: PropTypes.arrayOf(PropTypes.oneOfType([String, Number])),
31-
numberStyle: PropTypes.style,
29+
offset: Array as unknown as PropType<[number | string, number | string]>,
30+
numberStyle: Object as PropType<CSSProperties>,
3231
title: String,
33-
};
32+
});
3433

35-
export type BadgeProps = Partial<ExtractPropTypes<typeof badgeProps>>;
34+
export type BadgeProps = Partial<ExtractPropTypes<ReturnType<typeof badgeProps>>>;
3635

3736
export default defineComponent({
3837
name: 'ABadge',
3938
Ribbon,
4039
inheritAttrs: false,
41-
props: badgeProps,
40+
props: badgeProps(),
4241
slots: ['text', 'count'],
4342
setup(props, { slots, attrs }) {
4443
const { prefixCls, direction } = useConfigInject('badge', props);
@@ -197,7 +196,7 @@ export default defineComponent({
197196
const transitionProps = getTransitionProps(children ? `${pre}-zoom` : '', {
198197
appear: false,
199198
});
200-
let scrollNumberStyle: CSSProperties = { ...mergedStyle, ...props.numberStyle };
199+
let scrollNumberStyle: CSSProperties = { ...mergedStyle, ...(props.numberStyle as object) };
201200
if (color && !isPresetColor(color)) {
202201
scrollNumberStyle = scrollNumberStyle || {};
203202
scrollNumberStyle.background = color;

components/badge/Ribbon.tsx

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
import type { LiteralUnion } from '../_util/type';
2-
import { tuple } from '../_util/type';
32
import type { PresetColorType } from '../_util/colors';
43
import { isPresetColor } from './utils';
54
import type { CSSProperties, PropType, ExtractPropTypes } from 'vue';
65
import { defineComponent, computed } from 'vue';
76
import PropTypes from '../_util/vue-types';
87
import useConfigInject from '../_util/hooks/useConfigInject';
98

10-
export const ribbonProps = {
9+
export const ribbonProps = () => ({
1110
prefix: String,
1211
color: { type: String as PropType<LiteralUnion<PresetColorType, string>> },
1312
text: PropTypes.any,
14-
placement: PropTypes.oneOf(tuple('start', 'end')).def('end'),
15-
};
13+
placement: { type: String as PropType<'start' | 'end'>, default: 'end' },
14+
});
1615

17-
export type RibbonProps = Partial<ExtractPropTypes<typeof ribbonProps>>;
16+
export type RibbonProps = Partial<ExtractPropTypes<ReturnType<typeof ribbonProps>>>;
1817

1918
export default defineComponent({
2019
name: 'ABadgeRibbon',
2120
inheritAttrs: false,
22-
props: ribbonProps,
21+
props: ribbonProps(),
2322
slots: ['text'],
2423
setup(props, { attrs, slots }) {
2524
const { prefixCls, direction } = useConfigInject('ribbon', props);

components/badge/ScrollNumber.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import useConfigInject from '../_util/hooks/useConfigInject';
77
import SingleNumber from './SingleNumber';
88
import { filterEmpty } from '../_util/props-util';
99

10-
export const scrollNumberProps = {
10+
const scrollNumberProps = {
1111
prefixCls: String,
1212
count: PropTypes.any,
1313
component: String,
14-
title: PropTypes.oneOfType([PropTypes.number, PropTypes.string, null]),
14+
title: PropTypes.any,
1515
show: Boolean,
1616
};
1717

components/breadcrumb/Breadcrumb.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface Route {
1414
children?: Omit<Route, 'children'>[];
1515
}
1616

17-
export const breadcrumbProps = {
17+
export const breadcrumbProps = () => ({
1818
prefixCls: String,
1919
routes: { type: Array as PropType<Route[]> },
2020
params: PropTypes.any,
@@ -24,9 +24,9 @@ export const breadcrumbProps = {
2424
(opt: { route: Route; params: unknown; routes: Route[]; paths: string[] }) => VueNode
2525
>,
2626
},
27-
};
27+
});
2828

29-
export type BreadcrumbProps = Partial<ExtractPropTypes<typeof breadcrumbProps>>;
29+
export type BreadcrumbProps = Partial<ExtractPropTypes<ReturnType<typeof breadcrumbProps>>>;
3030

3131
function getBreadcrumbName(route: Route, params: unknown) {
3232
if (!route.breadcrumbName) {
@@ -53,7 +53,7 @@ function defaultItemRender(opt: {
5353

5454
export default defineComponent({
5555
name: 'ABreadcrumb',
56-
props: breadcrumbProps,
56+
props: breadcrumbProps(),
5757
slots: ['separator', 'itemRender'],
5858
setup(props, { slots }) {
5959
const { prefixCls, direction } = useConfigInject('breadcrumb', props);

0 commit comments

Comments
 (0)