forked from sindresorhus/p-debounce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
52 lines (43 loc) · 1.59 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
declare namespace pDebounce {
interface Options {
/**
Call the `fn` on the [leading edge of the timeout](https://css-tricks.com/debouncing-throttling-explained-examples/#article-header-id-1). Meaning immediately, instead of waiting for `wait` milliseconds.
@default false
*/
readonly leading?: boolean;
}
}
declare const pDebounce: {
/**
[Debounce](https://css-tricks.com/debouncing-throttling-explained-examples/) promise-returning & async functions.
@param fn - Promise-returning/async function to debounce.
@param wait - Milliseconds to wait before calling `fn`.
@returns A function that delays calling `fn` until after `wait` milliseconds have elapsed since the last time it was called.
@example
```
import pDebounce = require('p-debounce');
const expensiveCall = async input => input;
const debouncedFn = pDebounce(expensiveCall, 200);
for (const i of [1, 2, 3]) {
debouncedFn(i).then(console.log);
}
//=> 3
//=> 3
//=> 3
```
*/
<ArgumentsType extends unknown[], ReturnType>(
fn: (...arguments: ArgumentsType) => PromiseLike<ReturnType> | ReturnType,
wait: number,
options?: pDebounce.Options
): (...arguments: ArgumentsType) => Promise<ReturnType>;
// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function pDebounce<ArgumentsType extends unknown[], ReturnType>(
// fn: (...arguments: ArgumentsType) => PromiseLike<ReturnType> | ReturnType,
// wait: number,
// options?: pDebounce.Options
// ): (...arguments: ArgumentsType) => Promise<ReturnType>;
// export = pDebounce;
default: typeof pDebounce;
};
export = pDebounce;