-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
index.test-d.ts
46 lines (37 loc) · 1.31 KB
/
index.test-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
import {expectType} from 'tsd';
import pThrottle, {type ThrottledFunction} from './index.js';
const unicornController = new AbortController();
const throttledUnicorn = pThrottle({
limit: 1,
interval: 1000,
signal: unicornController.signal,
})((_index: string) => '🦄');
const lazyUnicornController = new AbortController();
const throttledLazyUnicorn = pThrottle({
limit: 1,
interval: 1000,
signal: lazyUnicornController.signal,
})(async (_index: string) => '🦄');
const taggedUnicornController = new AbortController();
const throttledTaggedUnicorn = pThrottle({
limit: 1,
interval: 1000,
signal: taggedUnicornController.signal,
})((_index: number, tag: string) => `${tag}: 🦄`);
expectType<string>(throttledUnicorn(''));
expectType<string>(await throttledLazyUnicorn(''));
expectType<string>(throttledTaggedUnicorn(1, 'foo'));
unicornController.abort();
lazyUnicornController.abort();
taggedUnicornController.abort();
expectType<boolean>(throttledUnicorn.isEnabled);
expectType<number>(throttledUnicorn.queueSize);
/* Generic */
declare function genericFunction<T>(argument: T): Promise<T>;
const throttledGenericFunction = pThrottle({
limit: 1,
interval: 1000,
})(genericFunction);
expectType<string>(await throttledGenericFunction('test'));
expectType<number>(await throttledGenericFunction(123));
/* /Generic */