export function promisify(f: (cb: (err: any, res: T) => void) => void, thisContext?: any): () => Promise; export function promisify(f: (arg: A, cb: (err: any, res: T) => void) => void, thisContext?: any): (arg: A) => Promise; export function promisify(f: (arg: A, arg2: A2, cb: (err: any, res: T) => void) => void, thisContext?: any): (arg: A, arg2: A2) => Promise; export function promisify(f: (arg: A, arg2: A2, arg3: A3, cb: (err: any, res: T) => void) => void, thisContext?: any): (arg: A, arg2: A2, arg3: A3) => Promise; export function promisify(f: (arg: A, arg2: A2, arg3: A3, arg4: A4, cb: (err: any, res: T) => void) => void, thisContext?: any): (arg: A, arg2: A2, arg3: A3, arg4: A4) => Promise; export function promisify(f: (arg: A, arg2: A2, arg3: A3, arg4: A4, arg5: A5, cb: (err: any, res: T) => void) => void, thisContext?: any): (arg: A, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => Promise; export function promisify(f: any, thisContext?: any) { return function () { const args = Array.prototype.slice.call(arguments); return new Promise((resolve, reject) => { args.push((err: any, result: any) => err !== null ? reject(err) : resolve(result)); f.apply(thisContext, args); }); }; } export function map(elts: PromiseLike[]>, f: (t: T) => U | PromiseLike): Promise; export function map(elts: PromiseLike, f: (t: T) => U | PromiseLike): Promise; export function map(elts: PromiseLike[], f: (t: T) => U | PromiseLike): Promise; export function map(elts: T[], f: (t: T) => U | PromiseLike): Promise; export function map(elts: any, f: any) { const apply = (appElts: any) => Promise.all(appElts.map((elt: any) => typeof elt.then === 'function' ? elt.then(f) : f(elt))); return typeof elts.then === 'function' ? elts.then(apply) : apply(elts); } export function _try(f: () => T): Promise; export function _try(f: (arg: any) => T, arg: any): Promise; export function _try(f: (arg: any, arg2: any) => T, arg: any, arg2: any): Promise; export function _try(f: (arg: any, arg2: any, arg3: any) => T, arg: any, arg2: any, arg3: any): Promise; export function _try(f: (arg: any, arg2: any, arg3: any, arg4: any) => T, arg: any, arg2: any, arg3: any, arg4: any): Promise; export function _try(f: any, thisContext?: any) { const args = Array.prototype.slice.call(arguments); return new Promise((res, rej) => { try { args.shift(); res(f.apply(thisContext, args)); } catch (err) { rej(err); } }); }