From 1503364d6be7b699398308e91cc4eb69c01fc4e3 Mon Sep 17 00:00:00 2001 From: tanjinzhou <415800467@qq.com> Date: Tue, 13 Oct 2020 15:39:08 +0800 Subject: [PATCH] perf: update ts types --- components/back-top/index.tsx | 3 ++- components/badge/Badge.tsx | 6 +++--- components/badge/ScrollNumber.tsx | 15 ++++++++------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/components/back-top/index.tsx b/components/back-top/index.tsx index 7453f914f..b1b5e957c 100644 --- a/components/back-top/index.tsx +++ b/components/back-top/index.tsx @@ -19,6 +19,7 @@ const BackTop = defineComponent({ name: 'ABackTop', inheritAttrs: false, mixins: [BaseMixin], + emits: ['click'], props: { ...props, visibilityHeight: PropTypes.number.def(400), @@ -57,7 +58,7 @@ const BackTop = defineComponent({ return targetNode.scrollTop; }, - scrollToTop(e) { + scrollToTop(e: Event) { const { target = getDefaultTarget } = this; scrollTo(0, { getContainer: target, diff --git a/components/badge/Badge.tsx b/components/badge/Badge.tsx index d81e1c653..d7f80928d 100644 --- a/components/badge/Badge.tsx +++ b/components/badge/Badge.tsx @@ -79,7 +79,7 @@ export default defineComponent({ } : { ...numberStyle }; }, - getBadgeClassName(prefixCls, children) { + getBadgeClassName(prefixCls: string, children: any[]) { const hasStatus = this.hasStatus(); return classNames(prefixCls, { [`${prefixCls}-status`]: hasStatus, @@ -111,7 +111,7 @@ export default defineComponent({ return (isEmpty || (isZero && !showZero)) && !isDot; }, - renderStatusText(prefixCls) { + renderStatusText(prefixCls: string) { const text = getComponent(this, 'text'); const hidden = this.isHidden(); return hidden || !text ? null : {text}; @@ -132,7 +132,7 @@ export default defineComponent({ ); }, - renderBadgeNumber(prefixCls, scrollNumberPrefixCls) { + renderBadgeNumber(prefixCls: string, scrollNumberPrefixCls: string) { const { status, color } = this.$props; const count = this.badgeCount; const displayCount = this.getDispayCount(); diff --git a/components/badge/ScrollNumber.tsx b/components/badge/ScrollNumber.tsx index 3e5d945be..581686bf6 100644 --- a/components/badge/ScrollNumber.tsx +++ b/components/badge/ScrollNumber.tsx @@ -6,7 +6,7 @@ import { cloneElement } from '../_util/vnode'; import { defaultConfigProvider } from '../config-provider'; import { CSSProperties, defineComponent, inject } from 'vue'; -function getNumberArray(num) { +function getNumberArray(num: string | number | undefined | null) { return num ? num .toString() @@ -33,6 +33,7 @@ export default defineComponent({ mixins: [BaseMixin], inheritAttrs: false, props: ScrollNumberProps, + emits: ['animated'], setup() { return { configProvider: inject('configProvider', defaultConfigProvider), @@ -81,12 +82,12 @@ export default defineComponent({ this.timeout = undefined; } }, - getPositionByNum(num, i) { + getPositionByNum(num: number, i: number) { const { sCount } = this; const currentCount = Math.abs(Number(sCount)); const lastCount = Math.abs(Number(this.lastCount)); - const currentDigit = Math.abs(getNumberArray(sCount)[i]); - const lastDigit = Math.abs(getNumberArray(this.lastCount)[i]); + const currentDigit = Math.abs(getNumberArray(sCount)[i] as number); + const lastDigit = Math.abs(getNumberArray(this.lastCount)[i] as number); if (this.animateStarted) { return 10 + num; @@ -107,7 +108,7 @@ export default defineComponent({ this.$emit('animated'); }, - renderNumberList(position, className) { + renderNumberList(position: number, className: string) { const childrenToReturn = []; for (let i = 0; i < 30; i++) { childrenToReturn.push( @@ -124,7 +125,7 @@ export default defineComponent({ return childrenToReturn; }, - renderCurrentNumber(prefixCls, num, i) { + renderCurrentNumber(prefixCls: string, num: number | string, i: number) { if (typeof num === 'number') { const position = this.getPositionByNum(num, i); const removeTransition = @@ -148,7 +149,7 @@ export default defineComponent({ ); }, - renderNumberElement(prefixCls) { + renderNumberElement(prefixCls: string) { const { sCount } = this; if (sCount && Number(sCount) % 1 === 0) { return getNumberArray(sCount)