diff --git a/types/p-try/index.d.ts b/types/p-try/index.d.ts index 82eca22d8c..9c76ef19e1 100644 --- a/types/p-try/index.d.ts +++ b/types/p-try/index.d.ts @@ -1,8 +1,16 @@ -// Type definitions for p-try 1.0 +// Type definitions for p-try 2.0 // Project: https://github.com/sindresorhus/p-try#readme // Definitions by: BendingBender +// Linus Unnebäck // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped export = pTry; +declare function pTry(cb: (a: A, b: B, c: C, d: D, e: E, f: F, ...args: any[]) => Promise | PromiseLike | T, a: A, b: B, c: C, d: D, e: E, f: F, ...args: any[]): Promise; +declare function pTry(cb: (a: A, b: B, c: C, d: D, e: E, f: F) => Promise | PromiseLike | T, a: A, b: B, c: C, d: D, e: E, f: F): Promise; +declare function pTry(cb: (a: A, b: B, c: C, d: D, e: E) => Promise | PromiseLike | T, a: A, b: B, c: C, d: D, e: E): Promise; +declare function pTry(cb: (a: A, b: B, c: C, d: D) => Promise | PromiseLike | T, a: A, b: B, c: C, d: D): Promise; +declare function pTry(cb: (a: A, b: B, c: C) => Promise | PromiseLike | T, a: A, b: B, c: C): Promise; +declare function pTry(cb: (a: A, b: B) => Promise | PromiseLike | T, a: A, b: B): Promise; +declare function pTry(cb: (a: A) => Promise | PromiseLike | T, a: A): Promise; declare function pTry(cb: () => Promise | PromiseLike | T): Promise; diff --git a/types/p-try/p-try-tests.ts b/types/p-try/p-try-tests.ts index 054d92e22f..d4db28020e 100644 --- a/types/p-try/p-try-tests.ts +++ b/types/p-try/p-try-tests.ts @@ -14,3 +14,23 @@ pTry(() => Promise.resolve('foo')).then(value => { pTry(throws).then(value => { str = value; }); + +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; + +pTry(a, 'test').then(v => { str = v; }); +pTry(b, 'test', 1).then(v => { str = v; }); +pTry(c, 'test', 1, false).then(v => { str = v; }); +pTry(d, 'test', 1, false, Symbol('test')).then(v => { str = v; }); +pTry(e, 'test', 1, false, Symbol('test'), 'no').then(v => { str = v; }); +pTry(f, 'test', 1, false, Symbol('test'), 'no', 2).then(v => { str = v; }); +pTry(g, 'test', 1, false, Symbol('test'), 'no', 2, true).then(v => { str = v; }); + +declare function add(...args: number[]): number; + +pTry(add, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13).then(v => (v === 91));