UNPKG

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