types: improve typing (#309)

This commit is contained in:
xiaoboost
2019-10-16 22:31:40 +08:00
committed by Evan You
parent b54c05f751
commit 32499b16e7
4 changed files with 9 additions and 7 deletions

View File

@@ -213,12 +213,12 @@ function debounce<T extends (...args: any[]) => any>(
fn: T,
delay: number = 300
): T {
let prevTimer: NodeJS.Timeout | null = null
let prevTimer: number | null = null
return ((...args: any[]) => {
if (prevTimer) {
clearTimeout(prevTimer)
}
prevTimer = setTimeout(() => {
prevTimer = window.setTimeout(() => {
fn(...args)
prevTimer = null
}, delay)