p-try: upgrade typings for v2.0

This commit is contained in:
Linus Unnebäck
2018-06-15 09:49:58 +01:00
parent 56265d81d4
commit 5d975a17db
2 changed files with 29 additions and 1 deletions

View File

@@ -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 <https://github.com/BendingBender>
// Linus Unnebäck <https://github.com/LinusU>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = pTry;
declare function pTry<T, A, B, C, D, E, F>(cb: (a: A, b: B, c: C, d: D, e: E, f: F, ...args: any[]) => Promise<T> | PromiseLike<T> | T, a: A, b: B, c: C, d: D, e: E, f: F, ...args: any[]): Promise<T>;
declare function pTry<T, A, B, C, D, E, F>(cb: (a: A, b: B, c: C, d: D, e: E, f: F) => Promise<T> | PromiseLike<T> | T, a: A, b: B, c: C, d: D, e: E, f: F): Promise<T>;
declare function pTry<T, A, B, C, D, E>(cb: (a: A, b: B, c: C, d: D, e: E) => Promise<T> | PromiseLike<T> | T, a: A, b: B, c: C, d: D, e: E): Promise<T>;
declare function pTry<T, A, B, C, D>(cb: (a: A, b: B, c: C, d: D) => Promise<T> | PromiseLike<T> | T, a: A, b: B, c: C, d: D): Promise<T>;
declare function pTry<T, A, B, C>(cb: (a: A, b: B, c: C) => Promise<T> | PromiseLike<T> | T, a: A, b: B, c: C): Promise<T>;
declare function pTry<T, A, B>(cb: (a: A, b: B) => Promise<T> | PromiseLike<T> | T, a: A, b: B): Promise<T>;
declare function pTry<T, A>(cb: (a: A) => Promise<T> | PromiseLike<T> | T, a: A): Promise<T>;
declare function pTry<T>(cb: () => Promise<T> | PromiseLike<T> | T): Promise<T>;

View File

@@ -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));