diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..219ab0c --- /dev/null +++ b/index.d.ts @@ -0,0 +1,408 @@ +// Utility types +type AnyFunction = (...args: any[]) => any; +type CallbackError = Error | null | undefined; + +type Last = + T extends [] ? never : + T extends [...infer _, infer R] ? R : + T extends [...infer _, (infer R)?] ? R | undefined: + never; + +type ExceptLast = T extends [ ...infer Head, any ] ? Head : any[]; + +type LastParameter any> = Last>; +type ParametersExceptLast any> = ExceptLast>; + +type SelectByOption = + O extends true ? TTrue : + O extends false ? TFalse : + TUndefined; + +type SelectByOptionOr = SelectByOption; + +type Opposite = + O extends true ? false : + O extends false ? true : + boolean; + +type Resolve = [T][0]; +// End of utility types + +type CallbackSingleReturnType< + T extends AnyFunction, + TCb extends AnyFunction = LastParameter, + TCbArgs = Parameters> +> = + TCbArgs extends [CallbackError?] ? void : + TCbArgs extends [CallbackError, infer U] ? U : + TCbArgs extends any[] ? TCbArgs[1] extends undefined ? void : TCbArgs[1]: + never; + +type CallbackMultiReturnType< + T extends AnyFunction, + TCb extends AnyFunction = LastParameter, + TCbArgs = Parameters> +> = + TCbArgs extends [any, ... infer U] ? U : + TCbArgs extends [any?, ... infer U] ? U : + TCbArgs extends [any] ? [] : + TCbArgs extends [any?] ? [] : + TCbArgs extends [] ? [] : + never; + +type CallbackWithoutErrorSingleReturnType = Parameters> extends [] ? void : Parameters>[0]; + +type CallbackWithoutErrorMultiReturnType = Parameters>; + +type CallbackReturn = SelectByOptionOr, CallbackSingleReturnType>, + SelectByOptionOr, CallbackWithoutErrorSingleReturnType>>; + +type PifiedFunction = Resolve<(...args:ParametersExceptLast) => Promise, GetErrorFirst>>>; + +type GetOption = + O extends {[F in Name]: true} ? true : + O extends {[F in Name]: false} ? false : + O extends {[F in Name]: boolean} ? boolean : + O extends {[F in Name]: undefined} ? Default : + Default; +type GetExcludeMain = Resolve>; +type GetErrorFirst = Resolve>; +type GetMultiArgs = Resolve>; + +type PossiblyPifiedFunction = Resolve, T>>; + +type PifiedObject = Resolve<{ + [Key in (keyof T)]: T[Key] extends AnyFunction ? PifiedFunction : T[Key]; +}>; + +type PifiedObjectFunction = Resolve< + GetExcludeMain extends true ? + T extends AnyFunction ? + ({} extends T ? T & PifiedObject : T) : + PifiedObject : + T extends AnyFunction ? + LastParameter extends never ? never : LastParameter extends AnyFunction ? + ({} extends T ? PifiedFunction & PifiedObject : PifiedFunction) : + never : + PifiedObject + >; + +interface PifyOptions { + /** + By default, the promisified function will only return the second argument from the callback, which works fine for most APIs. This option can be useful for modules like `request` that return multiple arguments. Turning this on will make it return an array of all arguments from the callback, excluding the error argument, instead of just the second argument. This also applies to rejections, where it returns an array of all the callback arguments, including the error. + @default false + @example + ``` + const request = require('request'); + const pify = require('pify'); + const pRequest = pify(request, {multiArgs: true}); + (async () => { + const [httpResponse, body] = await pRequest('https://sindresorhus.com'); + })(); + ``` + */ + multiArgs?: boolean, + + /** + Methods in a module to promisfy. Remaining methods will be left untouched. Does not affect typescript compile time types. + */ + include?: Array, + + /** + Methods in a module not to promisify. Methods with names ending with 'Sync' are excluded by default. Does not the type of return value in compile time. + @default [/.+(Sync|Stream)$/] + */ + exclude?: Array, + + /** + If the given module is a function itself, it will be promisified. Enable this option if you want to promisify only methods of the module. + @default false + @example + ``` + const pify = require('pify'); + function fn() { + return true; + } + fn.method = (data, callback) => { + setImmediate(() => { + callback(null, data); + }); + }; + (async () => { + // Promisify methods but not `fn()` + const promiseFn = pify(fn, {excludeMain: true}); + if (promiseFn()) { + console.log(await promiseFn.method('hi')); + } + })(); + ``` + */ + excludeMain?: boolean, + + /** + Whether the callback has an error as the first argument. You'll want to set this to false if you're dealing with an API that doesn't have an error as the first argument, like `fs.exists()`, some browser APIs, Chrome Extension APIs, etc. + @default true + */ + errorFirst?: boolean, + + /** + Custom promise module to use instead of the native one. + */ + promiseModule?: PromiseConstructor +} + +interface PifyOptionsMultiArgs0ErrorFirst1 extends PifyOptions { + multiArgs?: undefined | false; + errorFirst?: undefined | true; + excludeMain: false | undefined; +} +interface PifyOptionsMultiArgs0ErrorFirst0 extends PifyOptions { + multiArgs?: undefined | false; + errorFirst: false; + excludeMain: false | undefined; +} +interface PifyOptionsMultiArgs1ErrorFirst1 extends PifyOptions { + multiArgs: true; + errorFirst?: undefined | true; + excludeMain: false | undefined; +} +interface PifyOptionsMultiArgs1ErrorFirst0 extends PifyOptions { + multiArgs: true; + errorFirst: false; + excludeMain: false | undefined; +} + +/** +Returns a `Promise` wrapped version of the supplied function or module. +@param input - Callback-style function or module whose methods you want to promisify. +@returns Wrapped version of the supplied function or module. +@example +``` +const fs = require('fs'); +const pify = require('pify'); +(async () => { + // Promisify a single function + const data = await pify(fs.readFile)('package.json', 'utf8'); + console.log(JSON.parse(data).name); + //=> 'pify' + // Promisify all methods in a module + const data2 = await pify(fs).readFile('package.json', 'utf8'); + console.log(JSON.parse(data2).name); + //=> 'pify' +})(); +``` +*/ +declare function pify(fn:(cb: (r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): () => Promise<[R0, R1, R2, R3, R4]>; +declare function pify(fn:(cb: (r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): () => Promise<[R0, R1, R2, R3]>; +declare function pify(fn:(cb: (r0: R0, r1: R1, r2: R2) => any) => any, options:Options): () => Promise<[R0, R1, R2]>; +declare function pify(fn:(cb: (r0: R0, r1: R1) => any) => any, options:Options): () => Promise<[R0, R1]>; +declare function pify(fn:(cb: (r0: R0) => any) => any, options:Options): () => Promise<[R0]>; +declare function pify(fn:(cb: () => any) => any, options:Options): () => Promise<[]>; +declare function pify(fn:(a0: A0, cb: (r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0) => Promise<[R0, R1, R2, R3, R4]>; +declare function pify(fn:(a0: A0, cb: (r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0) => Promise<[R0, R1, R2, R3]>; +declare function pify(fn:(a0: A0, cb: (r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0) => Promise<[R0, R1, R2]>; +declare function pify(fn:(a0: A0, cb: (r0: R0, r1: R1) => any) => any, options:Options): (a0: A0) => Promise<[R0, R1]>; +declare function pify(fn:(a0: A0, cb: (r0: R0) => any) => any, options:Options): (a0: A0) => Promise<[R0]>; +declare function pify(fn:(a0: A0, cb: () => any) => any, options:Options): (a0: A0) => Promise<[]>; +declare function pify(fn:(a0: A0, a1: A1, cb: (r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1) => Promise<[R0, R1, R2, R3, R4]>; +declare function pify(fn:(a0: A0, a1: A1, cb: (r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1) => Promise<[R0, R1, R2, R3]>; +declare function pify(fn:(a0: A0, a1: A1, cb: (r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1) => Promise<[R0, R1, R2]>; +declare function pify(fn:(a0: A0, a1: A1, cb: (r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1) => Promise<[R0, R1]>; +declare function pify(fn:(a0: A0, a1: A1, cb: (r0: R0) => any) => any, options:Options): (a0: A0, a1: A1) => Promise<[R0]>; +declare function pify(fn:(a0: A0, a1: A1, cb: () => any) => any, options:Options): (a0: A0, a1: A1) => Promise<[]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise<[R0, R1, R2, R3, R4]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise<[R0, R1, R2, R3]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise<[R0, R1, R2]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise<[R0, R1]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (r0: R0) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise<[R0]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: () => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise<[]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise<[R0, R1, R2, R3, R4]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise<[R0, R1, R2, R3]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise<[R0, R1, R2]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise<[R0, R1]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (r0: R0) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise<[R0]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: () => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise<[]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise<[R0, R1, R2, R3, R4]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise<[R0, R1, R2, R3]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise<[R0, R1, R2]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise<[R0, R1]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (r0: R0) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise<[R0]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: () => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise<[]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise<[R0, R1, R2, R3, R4]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise<[R0, R1, R2, R3]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise<[R0, R1, R2]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise<[R0, R1]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (r0: R0) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise<[R0]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: () => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise<[]>; +declare function pify(fn:(cb: (r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): () => Promise; +declare function pify(fn:(cb: (r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): () => Promise; +declare function pify(fn:(cb: (r0: R0, r1: R1, r2: R2) => any) => any, options:Options): () => Promise; +declare function pify(fn:(cb: (r0: R0, r1: R1) => any) => any, options:Options): () => Promise; +declare function pify(fn:(cb: (r0: R0) => any) => any, options:Options): () => Promise; +declare function pify(fn:(cb: () => any) => any, options:Options): () => Promise; +declare function pify(fn:(a0: A0, cb: (r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, cb: (r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, cb: (r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, cb: (r0: R0, r1: R1) => any) => any, options:Options): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, cb: (r0: R0) => any) => any, options:Options): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, cb: () => any) => any, options:Options): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (r0: R0) => any) => any, options:Options): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: () => any) => any, options:Options): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (r0: R0) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: () => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (r0: R0) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: () => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (r0: R0) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: () => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (r0: R0) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: () => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): () => Promise<[R0, R1, R2, R3, R4]>; +declare function pify(fn:(cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): () => Promise<[R0, R1, R2, R3]>; +declare function pify(fn:(cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any, options:Options): () => Promise<[R0, R1, R2]>; +declare function pify(fn:(cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any, options:Options): () => Promise<[R0, R1]>; +declare function pify(fn:(cb: (error: Error | null | undefined, r0: R0) => any) => any, options:Options): () => Promise<[R0]>; +declare function pify(fn:(cb: (error: Error | null | undefined) => any) => any, options:Options): () => Promise<[]>; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0) => Promise<[R0, R1, R2, R3, R4]>; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0) => Promise<[R0, R1, R2, R3]>; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0) => Promise<[R0, R1, R2]>; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any, options:Options): (a0: A0) => Promise<[R0, R1]>; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined, r0: R0) => any) => any, options:Options): (a0: A0) => Promise<[R0]>; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined) => any) => any, options:Options): (a0: A0) => Promise<[]>; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1) => Promise<[R0, R1, R2, R3, R4]>; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1) => Promise<[R0, R1, R2, R3]>; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1) => Promise<[R0, R1, R2]>; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1) => Promise<[R0, R1]>; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined, r0: R0) => any) => any, options:Options): (a0: A0, a1: A1) => Promise<[R0]>; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined) => any) => any, options:Options): (a0: A0, a1: A1) => Promise<[]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise<[R0, R1, R2, R3, R4]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise<[R0, R1, R2, R3]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise<[R0, R1, R2]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise<[R0, R1]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined, r0: R0) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise<[R0]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise<[]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise<[R0, R1, R2, R3, R4]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise<[R0, R1, R2, R3]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise<[R0, R1, R2]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise<[R0, R1]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined, r0: R0) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise<[R0]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise<[]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise<[R0, R1, R2, R3, R4]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise<[R0, R1, R2, R3]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise<[R0, R1, R2]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise<[R0, R1]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined, r0: R0) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise<[R0]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise<[]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise<[R0, R1, R2, R3, R4]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise<[R0, R1, R2, R3]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise<[R0, R1, R2]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise<[R0, R1]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined, r0: R0) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise<[R0]>; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise<[]>; +declare function pify(fn:(cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): () => Promise; +declare function pify(fn:(cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): () => Promise; +declare function pify(fn:(cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any, options:Options): () => Promise; +declare function pify(fn:(cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any, options:Options): () => Promise; +declare function pify(fn:(cb: (error: Error | null | undefined, r0: R0) => any) => any, options:Options): () => Promise; +declare function pify(fn:(cb: (error: Error | null | undefined) => any) => any, options:Options): () => Promise; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any, options:Options): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined, r0: R0) => any) => any, options:Options): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined) => any) => any, options:Options): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined, r0: R0) => any) => any, options:Options): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined) => any) => any, options:Options): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined, r0: R0) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined, r0: R0) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined, r0: R0) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined, r0: R0) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined) => any) => any, options:Options): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any): () => Promise; +declare function pify(fn:(cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any): () => Promise; +declare function pify(fn:(cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any): () => Promise; +declare function pify(fn:(cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any): () => Promise; +declare function pify(fn:(cb: (error: Error | null | undefined, r0: R0) => any) => any): () => Promise; +declare function pify(fn:(cb: (error: Error | null | undefined) => any) => any): () => Promise; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined, r0: R0) => any) => any): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, cb: (error: Error | null | undefined) => any) => any): (a0: A0) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined, r0: R0) => any) => any): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, cb: (error: Error | null | undefined) => any) => any): (a0: A0, a1: A1) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined, r0: R0) => any) => any): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, cb: (error: Error | null | undefined) => any) => any): (a0: A0, a1: A1, a2: A2) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined, r0: R0) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, cb: (error: Error | null | undefined) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined, r0: R0) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, cb: (error: Error | null | undefined) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3, r4: R4) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2, r3: R3) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined, r0: R0, r1: R1, r2: R2) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined, r0: R0, r1: R1) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined, r0: R0) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; +declare function pify(fn:(a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, cb: (error: Error | null | undefined) => any) => any): (a0: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise; + +declare function pify(fn: T, options?: Options): PifiedObjectFunction; +export = pify; \ No newline at end of file diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..ad7dca3 --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,154 @@ +import {expectType, expectNotType, expectError, expectAssignable, printType} from 'tsd'; +import pify = require('.'); + +expectError(pify()); +expectError(pify(null)); +expectError(pify(undefined)); +expectError(pify(123)); +expectError(pify('abc')); +expectError(pify(null, {})); +expectError(pify(undefined, {})); +expectError(pify(123, {})); +expectError(pify('abc', {})); +expectError(pify((v: number) => {})()); + +type A1 = 'A1'; +type A2 = 'A2'; +type R1 = 'R1'; +type R2 = 'R2'; +let someBoolean:boolean = Math.random() > 0.5; +const a1:A1 = 'A1'; +const a2:A2 = 'A2'; + +let function00 = (cb: (err: Error | undefined) => any) => { }; +let function10 = (a1:A1, cb: (err: Error | undefined) => any) => { }; +let function20 = (a1:A1, a2:A2, cb: (err: Error | undefined) => any) => { }; + +let function01 = (cb: (err: Error | undefined, v1?:R1) => any) => { }; +let function11 = (a1:A1, cb: (err: Error | undefined, v1?:R1) => any) => { }; +let function21 = (a1:A1, a2:A2, cb: (err: Error | undefined, v1?:R1) => any) => { }; + +let function02 = (cb: (err: Error | undefined, v1?:R1, v2?:R2) => any) => { }; +let function12 = (a1:A1, cb: (err: Error | undefined, v1?:R1, v2?:R2) => any) => { }; +let function22 = (a1:A1, a2:A2, cb: (err: Error | undefined, v1?:R1, v2?:R2) => any) => { }; + +let functionNoError00 = (cb: () => any) => { }; +let functionNoError10 = (a1:A1, cb: () => any) => { }; +let functionNoError01 = (cb: (v1:R1) => any) => { }; +let functionNoError11 = (a1:A1, cb: (v1:R1) => any) => { }; + +expectType<() => Promise>(pify(functionNoError00, {errorFirst: false})); +expectType<() => Promise>(pify(functionNoError01, {errorFirst: false})); +expectType<(a1:A1) => Promise>(pify(functionNoError10, {errorFirst: false})); +expectType<(a1:A1) => Promise>(pify(functionNoError11, {errorFirst: false})); + +expectType<{}>(pify({})); +expectAssignable<{a: number, b: boolean, c: string}>(pify({a: 1, b: true, c: 'qwe'})); +expectType<{a: number, b: boolean, c: string}>(pify({a: 1, b: someBoolean, c: 'qwe'})); + +expectType<() => Promise>(pify(function00)); +expectType<(a1:A1) => Promise>(pify(function10)); +expectType<(a1:A1, a2:A2) => Promise>(pify(function20)); + +expectType<() => Promise>(pify(function00, {excludeMain: false})); +expectType<(a1:A1) => Promise>(pify(function10, {excludeMain: false})); +expectType<(a1:A1, a2:A2) => Promise>(pify(function20, {excludeMain: false})); + +expectType<() => Promise>(pify(function00, {errorFirst: true})); +expectType<(a1:A1) => Promise>(pify(function10, {errorFirst: true})); +expectType<(a1:A1, a2:A2) => Promise>(pify(function20, {errorFirst: true})); + +expectType<() => Promise>(pify(function00, {errorFirst: false})); +expectType<(a1:A1) => Promise>(pify(function10, {errorFirst: false})); +expectType<(a1:A1, a2:A2) => Promise>(pify(function20, {errorFirst: false})); + +expectType<() => Promise>(pify(function00, {errorFirst: true})); +expectType<(a1:A1) => Promise>(pify(function10, {errorFirst: true})); +expectType<(a1:A1, a2:A2) => Promise>(pify(function20, {errorFirst: true})); + +expectType<() => Promise<[Error | undefined]>>(pify(function00, {errorFirst: false, multiArgs: true})); +expectType<(a1:A1) => Promise<[Error | undefined]>>(pify(function10, {errorFirst: false, multiArgs: true})); +expectType<(a1:A1, a2:A2) => Promise<[Error | undefined]>>(pify(function20, {errorFirst: false, multiArgs: true})); + + +expectType(pify(function00, {excludeMain: true})); +expectType(pify(function10, {excludeMain: true})); +expectType(pify(function20, {excludeMain: true})); +expectType(pify(function01, {excludeMain: true})); +expectType(pify(function11, {excludeMain: true})); +expectType(pify(function21, {excludeMain: true})); +expectType(pify(function02, {excludeMain: true})); +expectType(pify(function12, {excludeMain: true})); +expectType(pify(function22, {excludeMain: true})); + + +expectAssignable(pify(function00, {excludeMain: someBoolean})); +expectAssignable(pify(function01, {excludeMain: someBoolean})); +expectAssignable(pify(function02, {excludeMain: someBoolean})); +expectAssignable(pify(function10, {excludeMain: someBoolean})); +expectAssignable(pify(function11, {excludeMain: someBoolean})); +expectAssignable(pify(function12, {excludeMain: someBoolean})); +expectAssignable(pify(function20, {excludeMain: someBoolean})); +expectAssignable(pify(function21, {excludeMain: someBoolean})); +expectAssignable(pify(function22, {excludeMain: someBoolean})); + +expectType<{ + function: () => Promise, + number: number, +}>(pify({ + function: function00, + number: 123, +})); + +expectAssignable<{ + function: () => Promise, + number: number, + string?: string, +}>(pify({ + function: function00, + number: 1, +})); + +expectNotType<{ + function: () => Promise, + string: string, + number: number, +}>(pify({ + function: function00, + string: 'qwe', +})); + +declare function generic10(a0:A0, cb:(error: Error | null | undefined) => any): any; +declare function generic01(cb:(error: Error | null | undefined, r0:R0) => any): any; +declare function generic11(a0:A0, cb:(error: Error | null | undefined, r0:R0) => any): any; + +expectType>((pify(generic01))()); +expectType>((pify(generic10))(a1)); +expectType>((pify(generic11))(a1)); + +declare function realLife1(url: string, callback: (error?: Error | null | undefined, response?: { statusCode: number }, body?: string) => void): void; +expectType<(url: string) => Promise<[{ statusCode: number }?, string?]>>(pify(realLife1, { multiArgs: true })) +declare function realLife2(url: string, callback: (response?: { statusCode: number }, body?: string) => void): void; +expectType<(url: string) => Promise<[{ statusCode: number }?, string?]>>(pify(realLife2, { multiArgs: true, errorFirst: false })) + +const fs = { + readFile(path: string, callback: (error?: Error, data?: Buffer) => void): void { + callback(undefined, Buffer.from('abc', 'utf8')); + }, + exists(path: string, callback: (result: boolean) => void): void { + callback(true); + }, +}; + +expectType<{ + readFile: (path: string) => Promise, + exists: (path: string) => Promise, +}>(pify(fs)); + +expectAssignable<{ + readFile: (path: string) => Promise, +}>(pify(fs, {exclude:['exists']})); + +expectAssignable<{ + exists: (path: string) => Promise, +}>(pify(fs, {exclude:['readFile'], errorFirst:false})); diff --git a/package.json b/package.json index ad75f0a..8a177b8 100644 --- a/package.json +++ b/package.json @@ -14,11 +14,12 @@ "node": ">=10" }, "scripts": { - "test": "xo && ava", + "test": "xo && ava && tsd", "optimization-test": "node --allow-natives-syntax optimization-test.js" }, "files": [ - "index.js" + "index.js", + "index.d.ts" ], "keywords": [ "promisify", @@ -43,6 +44,7 @@ "devDependencies": { "ava": "^2.4.0", "pinkie-promise": "^2.0.0", + "tsd": "^0.17.0", "v8-natives": "^1.1.0", "xo": "^0.26.1" }