index.d.ts 868 B

123456789101112131415161718192021222324
  1. type AnyFunction = (...arguments_: readonly any[]) => unknown;
  2. /**
  3. Creates a debounced function that delays execution until `wait` milliseconds have passed since its last invocation.
  4. Set 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.
  5. The returned function has a `.clear()` method to cancel scheduled executions, and a `.flush()` method for immediate execution and resetting the timer for future calls.
  6. */
  7. declare function debounce<F extends AnyFunction>(
  8. function_: F,
  9. wait?: number,
  10. options?: {immediate: boolean}
  11. ): debounce.DebouncedFunction<F>;
  12. declare namespace debounce {
  13. type DebouncedFunction<F extends AnyFunction> = {
  14. (...arguments_: Parameters<F>): ReturnType<F> | undefined;
  15. clear(): void;
  16. flush(): void;
  17. };
  18. }
  19. export = debounce;