UNPKG

3.07 kBTypeScriptView Raw
1/// <reference types="node" />
2
3import util = require("util");
4
5import polyfill = require("./implementation");
6import getUtilPromisify = require("./polyfill");
7import shimUtilPromisify = require("./shim");
8
9// eslint-disable-next-line @typescript-eslint/ban-types
10declare function promisify<TCustom extends Function>(fn: util.CustomPromisify<TCustom>): TCustom;
11
12declare function promisify<TResult>(
13 fn: (callback: (err: any, result: TResult) => void) => void,
14): () => Promise<TResult>;
15declare function promisify(fn: (callback: (err?: any) => void) => void): () => Promise<void>;
16
17declare function promisify<T1, TResult>(
18 fn: (arg1: T1, callback: (err: any, result: TResult) => void) => void,
19): (arg1: T1) => Promise<TResult>;
20declare function promisify<T1>(fn: (arg1: T1, callback: (err?: any) => void) => void): (arg1: T1) => Promise<void>;
21
22declare function promisify<T1, T2, TResult>(
23 fn: (arg1: T1, arg2: T2, callback: (err: any, result: TResult) => void) => void,
24): (arg1: T1, arg2: T2) => Promise<TResult>;
25declare function promisify<T1, T2>(
26 fn: (arg1: T1, arg2: T2, callback: (err?: any) => void) => void,
27): (arg1: T1, arg2: T2) => Promise<void>;
28
29declare function promisify<T1, T2, T3, TResult>(
30 fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err: any, result: TResult) => void) => void,
31): (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>;
32declare function promisify<T1, T2, T3>(
33 fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err?: any) => void) => void,
34): (arg1: T1, arg2: T2, arg3: T3) => Promise<void>;
35
36declare function promisify<T1, T2, T3, T4, TResult>(
37 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: any, result: TResult) => void) => void,
38): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>;
39declare function promisify<T1, T2, T3, T4>(
40 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err?: any) => void) => void,
41): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>;
42
43declare function promisify<T1, T2, T3, T4, T5, TResult>(
44 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: any, result: TResult) => void) => void,
45): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>;
46declare function promisify<T1, T2, T3, T4, T5>(
47 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err?: any) => void) => void,
48): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>;
49
50// eslint-disable-next-line @typescript-eslint/ban-types
51declare function promisify(fn: Function): Function;
52
53declare namespace promisify {
54 const custom: typeof polyfill.custom;
55
56 /**
57 * @deprecated
58 * Not exposed by native `util.promisify` or supported by browserify's `util.promisify`.
59 *
60 * Use `util.promisify.custom` instead.
61 */
62 const customPromisifyArgs: typeof polyfill.customPromisifyArgs | undefined;
63
64 function getPolyfill(): ReturnType<typeof getUtilPromisify>;
65 const implementation: typeof polyfill;
66 function shim(): ReturnType<typeof shimUtilPromisify>;
67}
68
69export = promisify;