mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
[p-throttle] introduce typings (#18675)
This commit is contained in:
committed by
Mohamed Hegazy
parent
71e42e2b62
commit
c441df954e
47
types/p-throttle/index.d.ts
vendored
Normal file
47
types/p-throttle/index.d.ts
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
// Type definitions for p-throttle 1.1
|
||||
// Project: https://github.com/sindresorhus/p-throttle#readme
|
||||
// Definitions by: BendingBender <https://github.com/BendingBender>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export = pThrottle;
|
||||
|
||||
declare function pThrottle<R>(fn: () => PromiseLike<R> | R, limit: number, interval: number): (() => Promise<R>) & { abort(): void; };
|
||||
declare function pThrottle<R, T1>(fn: (arg1: T1) => PromiseLike<R> | R, limit: number, interval: number): ((arg1: T1) => Promise<R>) & { abort(): void; };
|
||||
declare function pThrottle<R, T1, T2>(fn: (arg1: T1, arg2: T2) => PromiseLike<R> | R, limit: number, interval: number): ((arg1: T1, arg2: T2) => Promise<R>) & { abort(): void; };
|
||||
declare function pThrottle<R, T1, T2, T3>(fn: (arg1: T1, arg2: T2, arg3: T3) => PromiseLike<R> | R,
|
||||
limit: number,
|
||||
interval: number): ((arg1: T1, arg2: T2, arg3: T3) => Promise<R>) & { abort(): void; };
|
||||
declare function pThrottle<R, T1, T2, T3, T4>(fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => PromiseLike<R> | R,
|
||||
limit: number,
|
||||
interval: number): ((arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<R>) & { abort(): void; };
|
||||
declare function pThrottle<R, T1, T2, T3, T4, T5>(fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => PromiseLike<R> | R,
|
||||
limit: number,
|
||||
interval: number): ((arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<R>) & { abort(): void; };
|
||||
declare function pThrottle<R, T1, T2, T3, T4, T5, T6>(fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => PromiseLike<R> | R,
|
||||
limit: number,
|
||||
interval: number): ((arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<R>) & { abort(): void; };
|
||||
declare function pThrottle<R, T1, T2, T3, T4, T5, T6, T7>(
|
||||
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7) => PromiseLike<R> | R,
|
||||
limit: number,
|
||||
interval: number): ((arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7) => Promise<R>) & { abort(): void; };
|
||||
declare function pThrottle<R, T1, T2, T3, T4, T5, T6, T7, T8>(
|
||||
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8) => PromiseLike<R> | R,
|
||||
limit: number,
|
||||
interval: number): ((arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8) => Promise<R>) & { abort(): void; };
|
||||
declare function pThrottle<R, T1, T2, T3, T4, T5, T6, T7, T8, T9>(
|
||||
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9) => PromiseLike<R> | R,
|
||||
limit: number,
|
||||
interval: number): ((arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9) => Promise<R>) & { abort(): void; };
|
||||
declare function pThrottle<R, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(
|
||||
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9, arg10: T10) => PromiseLike<R> | R,
|
||||
limit: number,
|
||||
interval: number): ((arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9, arg10: T10) => Promise<R>) & { abort(): void; };
|
||||
declare function pThrottle<R>(fn: (...args: any[]) => PromiseLike<R> | R, limit: number, interval: number): ((...args: any[]) => Promise<R>) & { abort(): void; };
|
||||
|
||||
declare namespace pThrottle {
|
||||
class AbortError extends Error {
|
||||
readonly name: 'AbortError';
|
||||
|
||||
constructor();
|
||||
}
|
||||
}
|
||||
47
types/p-throttle/p-throttle-tests.ts
Normal file
47
types/p-throttle/p-throttle-tests.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import pThrottle = require('p-throttle');
|
||||
|
||||
const now = Date.now();
|
||||
|
||||
const throttled = pThrottle((i: number) => {
|
||||
const secDiff = ((Date.now() - now) / 1000).toFixed();
|
||||
return Promise.resolve(`${i}: ${secDiff}s`);
|
||||
}, 2, 1000);
|
||||
|
||||
for (let i = 1; i <= 6; i++) {
|
||||
throttled(i).then(res => {
|
||||
const str: string = res;
|
||||
});
|
||||
}
|
||||
|
||||
throttled.abort();
|
||||
|
||||
pThrottle(() => true, 2, 3).abort();
|
||||
pThrottle(() => true, 2, 3)();
|
||||
pThrottle((n: number, s: string) => true, 2, 3).abort();
|
||||
pThrottle((n: number, s: string) => true, 2, 3)(1, 's');
|
||||
pThrottle((n: number, s: string, b: boolean) => true, 2, 3).abort();
|
||||
pThrottle((n: number, s: string, b: boolean) => true, 2, 3)(1, 's', true);
|
||||
pThrottle((n: number, s: string, b: boolean, n2: number) => true, 2, 3).abort();
|
||||
pThrottle((n: number, s: string, b: boolean, n2: number) => true, 2, 3)(1, 's', true, 1);
|
||||
pThrottle((n: number, s: string, b: boolean, n2: number, s2: string) => true, 2, 3).abort();
|
||||
pThrottle((n: number, s: string, b: boolean, n2: number, s2: string) => true, 2, 3)(1, 's', true, 1, 's');
|
||||
pThrottle((n: number, s: string, b: boolean, n2: number, s2: string, b2: boolean) => true, 2, 3).abort();
|
||||
pThrottle((n: number, s: string, b: boolean, n2: number, s2: string, b2: boolean) => true, 2, 3)(1, 's', true, 1, 's', false);
|
||||
pThrottle((n: number, s: string, b: boolean, n2: number, s2: string, b2: boolean, n3: number) => true, 2, 3).abort();
|
||||
pThrottle((n: number, s: string, b: boolean, n2: number, s2: string, b2: boolean, n3: number) => true, 2, 3)(1, 's', true, 1, 's', false, 1);
|
||||
pThrottle((n: number, s: string, b: boolean, n2: number, s2: string, b2: boolean, n3: number, n4: number) => true, 2, 3).abort();
|
||||
pThrottle((n: number, s: string, b: boolean, n2: number, s2: string, b2: boolean, n3: number, n4: number) => true, 2, 3)(1, 's', true, 1, 's', false, 1, 2);
|
||||
pThrottle((n: number, s: string, b: boolean, n2: number, s2: string, b2: boolean, n3: number, n4: number, n5: number) => true, 2, 3).abort();
|
||||
pThrottle((n: number, s: string, b: boolean, n2: number, s2: string, b2: boolean, n3: number, n4: number, n5: number) => true, 2, 3)(1, 's', true, 1, 's', false, 1, 2, 3);
|
||||
pThrottle((n: number, s: string, b: boolean, n2: number, s2: string, b2: boolean, n3: number, n4: number, n5: number, n6: number) => true, 2, 3).abort();
|
||||
pThrottle((n: number, s: string, b: boolean, n2: number, s2: string, b2: boolean, n3: number, n4: number, n5: number, n6: number) => true, 2, 3)(1, 's', true, 1, 's', false, 1, 2, 3, 4);
|
||||
pThrottle(
|
||||
(n: number, s: string, b: boolean, n2: number, s2: string, b2: boolean, n3: number, n4: number, n5: number, n6: number, s3: string) => true,
|
||||
2,
|
||||
3).abort();
|
||||
pThrottle(
|
||||
(n: number, s: string, b: boolean, n2: number, s2: string, b2: boolean, n3: number, n4: number, n5: number, n6: number, s3: string) => true,
|
||||
2,
|
||||
3)(1, 's', true, 1, 's', false, 1, 2, 3, 4, 'as');
|
||||
|
||||
throw new pThrottle.AbortError();
|
||||
22
types/p-throttle/tsconfig.json
Normal file
22
types/p-throttle/tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"p-throttle-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/p-throttle/tslint.json
Normal file
1
types/p-throttle/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user