-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.d.ts
107 lines (83 loc) · 2.88 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Type definitions for zalgo-promise
// Inspired from below but moved to live inside the library
// --------------------------------------------------------------
// Project: https://github.com/krakenjs/zalgo-promise#readme
// Definitions by: Daniel Shuy <https://github.com/daniel-shuy>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// --------------------------------------------------------------
export type ResultType<P extends ZalgoPromise<any>> = P extends ZalgoPromise<
infer R
>
? R
: never;
export type FlattenPromises<T extends {}> = {
[K in keyof T]: T[K] extends ZalgoPromise<any> ? ResultType<T[K]> : T[K];
};
export class ZalgoPromise<R> {
constructor(
handler?: (
resolve: (result: R) => void,
reject: (error: any) => void
) => void
);
resolve(result: R): this;
reject(error: any): this;
asyncReject(error: any): this;
dispatch(): void;
then<X>(
onSuccess?: (result: R) => ZalgoPromise<X>,
onError?: (error: any) => ZalgoPromise<X>
): ZalgoPromise<X>;
then<Y>(
onSuccess?: (result: R) => Y,
onError?: (error: any) => Y
): ZalgoPromise<Y>;
// to support mixed promise/non-promise return types
then<X, Y>(
onSuccess: (result: R) => ZalgoPromise<X> | Y,
onError: (error: any) => ZalgoPromise<X> | Y
): ZalgoPromise<X | Y>;
catch<X>(onError: (error: any) => ZalgoPromise<X>): ZalgoPromise<X>;
catch<Y>(onError: (error: any) => Y): ZalgoPromise<Y>;
finally(onFinally: () => any): this;
timeout(time: number, err?: Error): this;
toPromise(): Promise<R>;
lazy(): this;
static resolve(): ZalgoPromise<void>;
static resolve<X>(value: ZalgoPromise<X>): ZalgoPromise<X>;
static resolve<Y>(value: Y): ZalgoPromise<Y>;
static reject(error: any): ZalgoPromise<any>;
static asyncReject(error: any): ZalgoPromise<any>;
static all<X extends readonly any[]>(
promises: X
): ZalgoPromise<FlattenPromises<X>>;
static hash<O extends {}>(promises: O): ZalgoPromise<FlattenPromises<O>>;
static map<T, X>(
items: readonly T[],
method: (item: T) => ZalgoPromise<X> | X
): ZalgoPromise<readonly X[]>;
static onPossiblyUnhandledException(handler: (err: any) => void): {
cancel: () => void;
};
// to support conditional promising returning method
static try<X, A extends readonly any[]>(
method: (...args: A) => ZalgoPromise<X> | undefined,
context?: any,
args?: Partial<A>
): ZalgoPromise<X | undefined>;
static try<X, A extends readonly any[]>(
method: (...args: A) => ZalgoPromise<X>,
context?: any,
args?: Partial<A>
): ZalgoPromise<X>;
static try<Y, A extends readonly any[]>(
method: (...args: A) => Y,
context?: any,
args?: Partial<A>
): ZalgoPromise<Y>;
static delay(delay: number): ZalgoPromise<void>;
static isPromise(value: any): boolean;
static flush(): ZalgoPromise<void>;
}
// UMD
export as namespace ZalgoPromise;