From 6f50bf79ec667417c40d2f6707d20206702b3836 Mon Sep 17 00:00:00 2001 From: cszhjh Date: Wed, 30 Oct 2024 21:05:43 +0800 Subject: [PATCH] fix: improve the type of parameter `fn` --- src/function.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/function.ts b/src/function.ts index c0d23c6..8b26d0c 100644 --- a/src/function.ts +++ b/src/function.ts @@ -2,7 +2,7 @@ import { isArray } from './general' export function NOOP() {} -export function debounce(fn: any, delay = 0) { +export function debounce(fn: (...args: any[]) => any, delay = 0) { let timer: any return function (this: unknown, ...args: any[]) { @@ -16,11 +16,11 @@ export function debounce(fn: any, delay = 0) { } } -export function throttle(fn: any, delay = 200): () => void { +export function throttle(fn: (...args: any[]) => any, delay = 200) { let timer: any let start = 0 - return function loop(this: unknown, ...args) { + return function loop(this: unknown, ...args: any[]) { const now = performance.now() const elapsed = now - start