diff --git a/types/p-limit/index.d.ts b/types/p-limit/index.d.ts index 416622298b..af0306cdd9 100644 --- a/types/p-limit/index.d.ts +++ b/types/p-limit/index.d.ts @@ -1,10 +1,18 @@ -// Type definitions for p-limit 1.1 +// Type definitions for p-limit 2.0 // Project: https://github.com/sindresorhus/p-limit#readme // Definitions by: BendingBender +// Linus Unnebäck // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare namespace pLimit {} - export = pLimit; -declare function pLimit(concurrency: number): (fn: () => PromiseLike) => Promise; +declare function limit(cb: (a: A, b: B, c: C, d: D, e: E, f: F, ...args: any[]) => PromiseLike | T, a: A, b: B, c: C, d: D, e: E, f: F, ...args: any[]): Promise; +declare function limit(cb: (a: A, b: B, c: C, d: D, e: E, f: F) => PromiseLike | T, a: A, b: B, c: C, d: D, e: E, f: F): Promise; +declare function limit(cb: (a: A, b: B, c: C, d: D, e: E) => PromiseLike | T, a: A, b: B, c: C, d: D, e: E): Promise; +declare function limit(cb: (a: A, b: B, c: C, d: D) => PromiseLike | T, a: A, b: B, c: C, d: D): Promise; +declare function limit(cb: (a: A, b: B, c: C) => PromiseLike | T, a: A, b: B, c: C): Promise; +declare function limit(cb: (a: A, b: B) => PromiseLike | T, a: A, b: B): Promise; +declare function limit(cb: (a: A) => PromiseLike | T, a: A): Promise; +declare function limit(cb: () => PromiseLike | T): Promise; + +declare function pLimit(concurrency: number): typeof limit; diff --git a/types/p-limit/p-limit-tests.ts b/types/p-limit/p-limit-tests.ts index e04b895e87..51dcb394fe 100644 --- a/types/p-limit/p-limit-tests.ts +++ b/types/p-limit/p-limit-tests.ts @@ -11,3 +11,25 @@ const input = [ Promise.all(input).then(result => { const str: string | undefined = result[0]; }); + +let str: string; + +declare function a(a: string): string; +declare function b(a: string, b: number): string; +declare function c(a: string, b: number, c: boolean): string; +declare function d(a: string, b: number, c: boolean, d: symbol): string; +declare function e(a: string, b: number, c: boolean, d: symbol, e: 'yes' | 'no'): string; +declare function f(a: string, b: number, c: boolean, d: symbol, e: 'yes' | 'no', f: 1 | 2): string; +declare function g(a: string, b: number, c: boolean, d: symbol, e: 'yes' | 'no', f: 1 | 2, g: true): string; + +limit(a, 'test').then(v => { str = v; }); +limit(b, 'test', 1).then(v => { str = v; }); +limit(c, 'test', 1, false).then(v => { str = v; }); +limit(d, 'test', 1, false, Symbol('test')).then(v => { str = v; }); +limit(e, 'test', 1, false, Symbol('test'), 'no').then(v => { str = v; }); +limit(f, 'test', 1, false, Symbol('test'), 'no', 2).then(v => { str = v; }); +limit(g, 'test', 1, false, Symbol('test'), 'no', 2, true).then(v => { str = v; }); + +declare function add(...args: number[]): number; + +limit(add, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13).then(v => (v === 91));