From e0063ae249473fe60492ebcae49b14a1ab121f57 Mon Sep 17 00:00:00 2001 From: Gavin <19986739+wjw-gavin@users.noreply.github.com> Date: Thu, 22 Sep 2022 11:24:32 +0800 Subject: [PATCH] perf: improve the type of setTimeout (#11069) * perf: improve the type of setTimeout with 'ReturnType' * fix: fix type 'number' is not assignable to type 'Timeout' Co-authored-by: wangjunwei --- packages/vant/src/image-preview/ImagePreviewItem.tsx | 2 +- packages/vant/src/notice-bar/NoticeBar.tsx | 2 +- packages/vant/src/notify/function-call.tsx | 4 ++-- packages/vant/src/stepper/Stepper.tsx | 2 +- packages/vant/src/swipe/Swipe.tsx | 2 +- packages/vant/src/toast/Toast.tsx | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/vant/src/image-preview/ImagePreviewItem.tsx b/packages/vant/src/image-preview/ImagePreviewItem.tsx index f60f4935b..381ea215b 100644 --- a/packages/vant/src/image-preview/ImagePreviewItem.tsx +++ b/packages/vant/src/image-preview/ImagePreviewItem.tsx @@ -140,7 +140,7 @@ export default defineComponent({ let startMoveY: number; let startScale: number; let startDistance: number; - let doubleTapTimer: NodeJS.Timeout | null; + let doubleTapTimer: ReturnType | null; let touchStartTime: number; const onTouchStart = (event: TouchEvent) => { diff --git a/packages/vant/src/notice-bar/NoticeBar.tsx b/packages/vant/src/notice-bar/NoticeBar.tsx index 69f64850b..d9ac8ceda 100644 --- a/packages/vant/src/notice-bar/NoticeBar.tsx +++ b/packages/vant/src/notice-bar/NoticeBar.tsx @@ -56,7 +56,7 @@ export default defineComponent({ setup(props, { emit, slots }) { let wrapWidth = 0; let contentWidth = 0; - let startTimer: NodeJS.Timeout; + let startTimer: ReturnType; const wrapRef = ref(); const contentRef = ref(); diff --git a/packages/vant/src/notify/function-call.tsx b/packages/vant/src/notify/function-call.tsx index 0fbc19fc4..9b79e93ef 100644 --- a/packages/vant/src/notify/function-call.tsx +++ b/packages/vant/src/notify/function-call.tsx @@ -3,7 +3,7 @@ import { mountComponent, usePopupState } from '../utils/mount-component'; import VanNotify from './Notify'; import type { NotifyMessage, NotifyOptions } from './types'; -let timer: number; +let timer: ReturnType; let instance: ComponentInstance; const parseOptions = (message: NotifyMessage | NotifyOptions) => @@ -55,7 +55,7 @@ export function showNotify(options: NotifyMessage | NotifyOptions) { clearTimeout(timer); if (options.duration! > 0) { - timer = window.setTimeout(closeNotify, options.duration); + timer = setTimeout(closeNotify, options.duration); } return instance; diff --git a/packages/vant/src/stepper/Stepper.tsx b/packages/vant/src/stepper/Stepper.tsx index 3d1832deb..7a50a7865 100644 --- a/packages/vant/src/stepper/Stepper.tsx +++ b/packages/vant/src/stepper/Stepper.tsx @@ -214,7 +214,7 @@ export default defineComponent({ }; let isLongPress: boolean; - let longPressTimer: NodeJS.Timeout; + let longPressTimer: ReturnType; const longPressStep = () => { longPressTimer = setTimeout(() => { diff --git a/packages/vant/src/swipe/Swipe.tsx b/packages/vant/src/swipe/Swipe.tsx index de2d75819..9a0702763 100644 --- a/packages/vant/src/swipe/Swipe.tsx +++ b/packages/vant/src/swipe/Swipe.tsx @@ -235,7 +235,7 @@ export default defineComponent({ }); }; - let autoplayTimer: NodeJS.Timeout; + let autoplayTimer: ReturnType; const stopAutoplay = () => clearTimeout(autoplayTimer); diff --git a/packages/vant/src/toast/Toast.tsx b/packages/vant/src/toast/Toast.tsx index 7e92b4850..940b15238 100644 --- a/packages/vant/src/toast/Toast.tsx +++ b/packages/vant/src/toast/Toast.tsx @@ -72,7 +72,7 @@ export default defineComponent({ emits: ['update:show'], setup(props, { emit, slots }) { - let timer: NodeJS.Timeout; + let timer: ReturnType; let clickable = false; const toggleClickable = () => {