10 lines
371 B
TypeScript
10 lines
371 B
TypeScript
export const debounce = <T extends (...args: any[]) => any>(
|
|
func: T,
|
|
delay: number
|
|
): ((...args: Parameters<T>) => void) => {
|
|
let timeoutId: ReturnType<typeof setTimeout>;
|
|
return function (this: ThisParameterType<T>, ...args: Parameters<T>) {
|
|
clearTimeout(timeoutId);
|
|
timeoutId = setTimeout(() => func.apply(this, args), delay);
|
|
};
|
|
}; |