Skip to content

Commit e2d4f8c

Browse files
committed
feat: update type
1 parent de77b01 commit e2d4f8c

File tree

13 files changed

+70
-79
lines changed

13 files changed

+70
-79
lines changed

components/_util/type.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,33 @@ export function eventType<T>() {
4747
return { type: [Function, Array] as PropType<T | T[]> };
4848
}
4949

50-
export function objectType<T>(defaultVal?: any) {
50+
export function objectType<T = {}>(defaultVal?: T) {
5151
return { type: Object as PropType<T>, default: defaultVal as T };
5252
}
5353

54-
export function booleanType(defaultVal?: any) {
54+
export function booleanType(defaultVal?: boolean) {
5555
return { type: Boolean, default: defaultVal as boolean };
5656
}
5757

58-
export function functionType<T = () => {}>(defaultVal?: any) {
58+
export function functionType<T = () => {}>(defaultVal?: T) {
5959
return { type: Function as PropType<T>, default: defaultVal as T };
6060
}
6161

62-
export function anyType<T = any>() {
63-
return { validator: () => true } as unknown as { type: PropType<T> };
62+
export function anyType<T = any>(defaultVal?: T) {
63+
return { validator: () => true, default: defaultVal as T } as unknown as { type: PropType<T> };
6464
}
6565
export function vNodeType<T = VueNode>() {
6666
return { validator: () => true } as unknown as { type: PropType<T> };
6767
}
6868

69-
export function stringType<T extends string = string>(defaultVal?: string) {
69+
export function arrayType<T extends any[]>(defaultVal?: T) {
70+
return { type: Array as unknown as PropType<T>, default: defaultVal as T };
71+
}
72+
73+
export function stringType<T extends string = string>(defaultVal?: T) {
7074
return { type: String as unknown as PropType<T>, default: defaultVal as T };
7175
}
7276

73-
export function someType<T>(types: any[], defaultVal?: any) {
77+
export function someType<T>(types: any[], defaultVal?: T) {
7478
return { type: types as PropType<T>, default: defaultVal as T };
7579
}

components/comment/style/index.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ const genBaseStyle: GenerateStyle<CommentToken> = token => {
141141
};
142142

143143
export default genComponentStyleHook('Comment', token => {
144-
console.log(token);
145144
const commentToken = mergeToken<CommentToken>(token, {
146145
commentBg: 'inherit',
147146
commentPaddingBase: `${token.paddingMD}px 0`,

components/list/index.en-US.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
category: Components
33
type: Data Display
44
title: List
5-
cover: https://gw.alipayobjects.com/zos/alicdn/5FrZKStG_/List.svg
5+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*EYuhSpw1iSwAAAAAAAAAAAAADrJ8AQ/original
66
---
77

88
Simple List.

components/list/index.tsx

+26-30
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { App, Plugin, ExtractPropTypes, PropType, HTMLAttributes } from 'vue';
22
import { provide, defineComponent, ref, watch, computed, toRef } from 'vue';
3-
import PropTypes from '../_util/vue-types';
43
import classNames from '../_util/classNames';
54

65
import type { SpinProps } from '../spin';
@@ -13,6 +12,14 @@ import Item from './Item';
1312
import { flattenChildren } from '../_util/props-util';
1413
import initDefaultProps from '../_util/props-util/initDefaultProps';
1514
import type { Key } from '../_util/type';
15+
import {
16+
arrayType,
17+
someType,
18+
booleanType,
19+
objectType,
20+
vNodeType,
21+
functionType,
22+
} from '../_util/type';
1623
import ItemMeta from './ItemMeta';
1724
import useConfigInject from '../config-provider/hooks/useConfigInject';
1825
import useBreakpoint from '../_util/hooks/useBreakpoint';
@@ -45,30 +52,22 @@ export type ListSize = 'small' | 'default' | 'large';
4552
export type ListItemLayout = 'horizontal' | 'vertical';
4653

4754
export const listProps = () => ({
48-
bordered: { type: Boolean, default: undefined },
49-
dataSource: PropTypes.array,
50-
extra: PropTypes.any,
51-
grid: { type: Object as PropType<ListGridType>, default: undefined as ListGridType },
55+
bordered: booleanType(),
56+
dataSource: arrayType(),
57+
extra: vNodeType(),
58+
grid: objectType<ListGridType>(),
5259
itemLayout: String as PropType<ListItemLayout>,
53-
loading: {
54-
type: [Boolean, Object] as PropType<boolean | (SpinProps & HTMLAttributes)>,
55-
default: undefined as boolean | (SpinProps & HTMLAttributes),
56-
},
57-
loadMore: PropTypes.any,
58-
pagination: {
59-
type: [Boolean, Object] as PropType<false | PaginationConfig>,
60-
default: undefined as false | PaginationConfig,
61-
},
60+
loading: someType<boolean | (SpinProps & HTMLAttributes)>([Boolean, Object]),
61+
loadMore: vNodeType(),
62+
pagination: someType<false | PaginationConfig>([Boolean, Object]),
6263
prefixCls: String,
63-
rowKey: [String, Number, Function] as PropType<Key | ((item: any) => Key)>,
64-
renderItem: Function as PropType<(opt: { item: any; index: number }) => any>,
64+
rowKey: someType<Key | ((item: any) => Key)>([String, Number, Function]),
65+
renderItem: functionType<(opt: { item: any; index: number }) => any>(),
6566
size: String as PropType<ListSize>,
66-
split: { type: Boolean, default: undefined },
67-
header: PropTypes.any,
68-
footer: PropTypes.any,
69-
locale: {
70-
type: Object as PropType<ListLocale>,
71-
},
67+
split: booleanType(),
68+
header: vNodeType(),
69+
footer: vNodeType(),
70+
locale: objectType<ListLocale>(),
7271
});
7372

7473
export interface ListLocale {
@@ -78,7 +77,6 @@ export interface ListLocale {
7877
export type ListProps = Partial<ExtractPropTypes<ReturnType<typeof listProps>>>;
7978

8079
import { ListContextKey } from './contextKey';
81-
import type { RenderEmptyHandler } from '../config-provider/renderEmpty';
8280

8381
const List = defineComponent({
8482
compatConfig: { MODE: 3 },
@@ -135,12 +133,6 @@ const List = defineComponent({
135133

136134
const onPaginationShowSizeChange = triggerPaginationEvent('onShowSizeChange');
137135

138-
const renderEmptyFunc = (renderEmptyHandler: RenderEmptyHandler) => (
139-
<div class={`${prefixCls.value}-empty-text`}>
140-
{props.locale?.emptyText || renderEmptyHandler('List')}
141-
</div>
142-
);
143-
144136
const loadingProp = computed(() => {
145137
if (typeof props.loading === 'boolean') {
146138
return {
@@ -304,7 +296,11 @@ const List = defineComponent({
304296
<ul class={`${prefixCls.value}-items`}>{items}</ul>
305297
);
306298
} else if (!children.length && !isLoading.value) {
307-
childrenContent = renderEmptyFunc(renderEmpty);
299+
childrenContent = (
300+
<div class={`${prefixCls.value}-empty-text`}>
301+
{props.locale?.emptyText || renderEmpty('List')}
302+
</div>
303+
);
308304
}
309305

310306
const paginationPosition = paginationProps.value.position || 'bottom';

components/list/index.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ category: Components
33
type: 数据展示
44
title: List
55
subtitle: 列表
6-
cover: https://gw.alipayobjects.com/zos/alicdn/5FrZKStG_/List.svg
6+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*EYuhSpw1iSwAAAAAAAAAAAAADrJ8AQ/original
77
---
88

99
通用列表。

components/page-header/index.tsx

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import { filterEmpty, flattenChildren, isEmptyContent } from '../_util/props-uti
55
import ArrowLeftOutlined from '@ant-design/icons-vue/ArrowLeftOutlined';
66
import ArrowRightOutlined from '@ant-design/icons-vue/ArrowRightOutlined';
77
import Breadcrumb from '../breadcrumb';
8+
import type { AvatarProps } from '../avatar';
89
import Avatar from '../avatar';
910
import TransButton from '../_util/transButton';
1011
import LocaleReceiver from '../locale-provider/LocaleReceiver';
11-
import { withInstall } from '../_util/type';
12+
import { objectType, vNodeType, withInstall } from '../_util/type';
1213
import useConfigInject from '../config-provider/hooks/useConfigInject';
1314
import classNames from '../_util/classNames';
1415
import ResizeObserver from '../vc-resize-observer';
@@ -20,15 +21,15 @@ import Space from '../space';
2021
import useStyle from './style';
2122

2223
export const pageHeaderProps = () => ({
23-
backIcon: PropTypes.any,
24+
backIcon: vNodeType(),
2425
prefixCls: String,
25-
title: PropTypes.any,
26-
subTitle: PropTypes.any,
26+
title: vNodeType(),
27+
subTitle: vNodeType(),
2728
breadcrumb: PropTypes.object,
28-
tags: PropTypes.any,
29-
footer: PropTypes.any,
30-
extra: PropTypes.any,
31-
avatar: PropTypes.object,
29+
tags: vNodeType(),
30+
footer: vNodeType(),
31+
extra: vNodeType(),
32+
avatar: objectType<AvatarProps>(),
3233
ghost: { type: Boolean, default: undefined },
3334
onBack: Function as PropType<MouseEventHandler>,
3435
});

components/page-header/style/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const genPageHeaderStyle: GenerateStyle<PageHeaderToken, CSSObject> = token => {
2424
...resetComponent(token),
2525
position: 'relative',
2626
padding: `${token.pageHeaderPaddingVertical}px ${token.pageHeaderPadding}px`,
27-
backgroundColor: token.colorBgLayout,
27+
backgroundColor: token.colorBgContainer,
2828

2929
[`${componentCls}-ghost`]: {
3030
backgroundColor: token.pageHeaderGhostBg,

components/statistic/Countdown.tsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ExtractPropTypes, PropType } from 'vue';
22
import { defineComponent, onBeforeUnmount, onMounted, onUpdated, ref } from 'vue';
33
import omit from '../_util/omit';
44
import initDefaultProps from '../_util/props-util/initDefaultProps';
5+
import { someType } from '../_util/type';
56
import Statistic, { statisticProps } from './Statistic';
67
import type { countdownValueType, FormatConfig, valueType } from './utils';
78
import { formatCountdown as formatCD } from './utils';
@@ -14,7 +15,7 @@ function getTime(value?: countdownValueType) {
1415
export const countdownProps = () => {
1516
return {
1617
...statisticProps(),
17-
value: [Number, String, Object] as PropType<countdownValueType>,
18+
value: someType<countdownValueType>([Number, String, Object]),
1819
format: String,
1920
onFinish: Function as PropType<() => void>,
2021
onChange: Function as PropType<(value?: countdownValueType) => void>,
@@ -67,13 +68,7 @@ export default defineComponent({
6768
}
6869
};
6970

70-
const formatCountdown = ({
71-
value,
72-
config,
73-
}: {
74-
value: countdownValueType;
75-
config: FormatConfig;
76-
}) => {
71+
const formatCountdown = ({ value, config }: { value: valueType; config: FormatConfig }) => {
7772
const { format } = props;
7873
return formatCD(value, { ...config, format });
7974
};

components/statistic/Number.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import padEnd from 'lodash-es/padEnd';
21
import type { FunctionalComponent, VNodeTypes } from 'vue';
32
import type { FormatConfig, valueType } from './utils';
43

@@ -27,7 +26,7 @@ const StatisticNumber: FunctionalComponent<NumberProps> = props => {
2726

2827
int = int.replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator);
2928
if (typeof precision === 'number') {
30-
decimal = padEnd(decimal, precision, '0').slice(0, precision > 0 ? precision : 0);
29+
decimal = decimal.padEnd(precision, '0').slice(0, precision > 0 ? precision : 0);
3130
}
3231

3332
if (decimal) {

components/statistic/Statistic.tsx

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
1-
import type { CSSProperties, ExtractPropTypes, PropType } from 'vue';
1+
import type { CSSProperties, ExtractPropTypes, PropType, VNode } from 'vue';
22
import { defineComponent } from 'vue';
3-
import PropTypes from '../_util/vue-types';
43
import initDefaultProps from '../_util/props-util/initDefaultProps';
54
import StatisticNumber from './Number';
6-
import type { valueType } from './utils';
5+
import type { valueType, Formatter } from './utils';
76
import Skeleton from '../skeleton/Skeleton';
87
import useConfigInject from '../config-provider/hooks/useConfigInject';
98

109
// CSSINJS
1110
import useStyle from './style';
11+
import { anyType, booleanType, functionType, someType, vNodeType } from '../_util/type';
1212

1313
export const statisticProps = () => ({
1414
prefixCls: String,
1515
decimalSeparator: String,
1616
groupSeparator: String,
1717
format: String,
18-
value: {
19-
type: [String, Number, Object] as PropType<valueType>,
20-
},
18+
value: someType<valueType>([Number, String, Object]),
2119
valueStyle: { type: Object as PropType<CSSProperties>, default: undefined as CSSProperties },
22-
valueRender: PropTypes.any,
23-
formatter: PropTypes.any,
20+
valueRender: functionType<(node: VNode | JSX.Element) => VNode | JSX.Element>(),
21+
formatter: anyType<Formatter>(),
2422
precision: Number,
25-
prefix: PropTypes.any,
26-
suffix: PropTypes.any,
27-
title: PropTypes.any,
28-
loading: { type: Boolean, default: undefined },
23+
prefix: vNodeType(),
24+
suffix: vNodeType(),
25+
title: vNodeType(),
26+
loading: booleanType(),
2927
});
3028

3129
export type StatisticProps = Partial<ExtractPropTypes<ReturnType<typeof statisticProps>>>;
@@ -52,7 +50,7 @@ export default defineComponent({
5250
const title = props.title ?? slots.title?.();
5351
const prefix = props.prefix ?? slots.prefix?.();
5452
const suffix = props.suffix ?? slots.suffix?.();
55-
const formatter = props.formatter ?? slots.formatter;
53+
const formatter = props.formatter ?? (slots.formatter as unknown as Formatter);
5654
// data-for-update just for update component
5755
// https://github.com/vueComponent/ant-design-vue/pull/3170
5856
let valueNode = (

components/statistic/index.en-US.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
category: Components
33
type: Data Display
44
title: Statistic
5-
cover: https://gw.alipayobjects.com/zos/antfincdn/rcBNhLBrKbE/Statistic.svg
5+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*YL7PRYNtH-4AAAAAAAAAAAAADrJ8AQ/original
66
---
77

88
Display statistic number.

components/statistic/index.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ category: Components
33
type: 数据展示
44
title: Statistic
55
subtitle: 统计数值
6-
cover: https://gw.alipayobjects.com/zos/antfincdn/rcBNhLBrKbE/Statistic.svg
6+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*YL7PRYNtH-4AAAAAAAAAAAAADrJ8AQ/original
77
---
88

99
展示统计数值。

components/statistic/utils.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import type { VNodeTypes } from 'vue';
2-
import padStart from 'lodash-es/padStart';
32

43
export type valueType = number | string;
5-
export type countdownValueType = valueType | Date;
4+
export type countdownValueType = number | string;
65

76
export type Formatter =
87
| false
@@ -41,12 +40,12 @@ export function formatTimeStr(duration: number, format: string) {
4140
const templateText = format.replace(escapeRegex, '[]');
4241

4342
const replacedText = timeUnits.reduce((current, [name, unit]) => {
44-
if (current.indexOf(name) !== -1) {
43+
if (current.includes(name)) {
4544
const value = Math.floor(leftDuration / unit);
4645
leftDuration -= value * unit;
4746
return current.replace(new RegExp(`${name}+`, 'g'), (match: string) => {
4847
const len = match.length;
49-
return padStart(value.toString(), len, '0');
48+
return value.toString().padStart(len, '0');
5049
});
5150
}
5251
return current;
@@ -60,7 +59,7 @@ export function formatTimeStr(duration: number, format: string) {
6059
});
6160
}
6261

63-
export function formatCountdown(value: countdownValueType, config: CountdownFormatConfig) {
62+
export function formatCountdown(value: valueType, config: CountdownFormatConfig) {
6463
const { format = '' } = config;
6564
const target = new Date(value).getTime();
6665
const current = Date.now();

0 commit comments

Comments
 (0)