UNPKG

868 BTypeScriptView Raw
1type AnyFunction = (...arguments_: readonly any[]) => unknown;
2
3/**
4Creates a debounced function that delays execution until `wait` milliseconds have passed since its last invocation.
5
6Set the `immediate` option to `true` to invoke the function immediately at the start of the `wait` interval, preventing issues such as double-clicks on a button.
7
8The returned function has a `.clear()` method to cancel scheduled executions, and a `.flush()` method for immediate execution and resetting the timer for future calls.
9*/
10declare function debounce<F extends AnyFunction>(
11 function_: F,
12 wait?: number,
13 options?: {immediate: boolean}
14): debounce.DebouncedFunction<F>;
15
16declare namespace debounce {
17 type DebouncedFunction<F extends AnyFunction> = {
18 (...arguments_: Parameters<F>): ReturnType<F> | undefined;
19 clear(): void;
20 flush(): void;
21 };
22}
23
24export = debounce;