forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es6-promise.d.ts
146 lines (136 loc) · 8.06 KB
/
es6-promise.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* tslint:disable */
// Type definitions for es6-promise
// Project: https://github.com/jakearchibald/ES6-Promise
// Definitions by: François de Campredon <https://github.com/fdecampredon/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
interface PromiseLike<T> {
then<U>(onFulfilled?: (value: T) => PromiseLike<U>, onRejected?: (error: any) => PromiseLike<U>): PromiseLike<U>;
then<U>(onFulfilled?: (value: T) => PromiseLike<U>, onRejected?: (error: any) => U): PromiseLike<U>;
then<U>(onFulfilled?: (value: T) => PromiseLike<U>, onRejected?: (error: any) => void): PromiseLike<U>;
then<U>(onFulfilled?: (value: T) => U, onRejected?: (error: any) => PromiseLike<U>): PromiseLike<U>;
then<U>(onFulfilled?: (value: T) => U, onRejected?: (error: any) => U): PromiseLike<U>;
then<U>(onFulfilled?: (value: T) => U, onRejected?: (error: any) => void): PromiseLike<U>;
}
interface Promise<T> extends PromiseLike<T> {
/**
* onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects.
* Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called.
* Both callbacks have a single parameter , the fulfillment value or rejection reason.
* "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve.
* If an error is thrown in the callback, the returned promise rejects with that error.
* @param onFulfilled called when/if "promise" resolves
* @param onRejected called when/if "promise" rejects
*/
then<U>(onFulfilled?: (value: T) => PromiseLike<U>, onRejected?: (error: any) => PromiseLike<U>): Promise<U>;
/**
* onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects.
* Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called.
* Both callbacks have a single parameter , the fulfillment value or rejection reason.
* "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve.
* If an error is thrown in the callback, the returned promise rejects with that error.
* @param onFulfilled called when/if "promise" resolves
* @param onRejected called when/if "promise" rejects
*/
then<U>(onFulfilled?: (value: T) => PromiseLike<U>, onRejected?: (error: any) => U): Promise<U>;
/**
* onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects.
* Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called.
* Both callbacks have a single parameter , the fulfillment value or rejection reason.
* "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve.
* If an error is thrown in the callback, the returned promise rejects with that error.
* @param onFulfilled called when/if "promise" resolves
* @param onRejected called when/if "promise" rejects
*/
then<U>(onFulfilled?: (value: T) => PromiseLike<U>, onRejected?: (error: any) => void): Promise<U>;
/**
* onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects.
* Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called.
* Both callbacks have a single parameter , the fulfillment value or rejection reason.
* "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve.
* If an error is thrown in the callback, the returned promise rejects with that error.
* @param onFulfilled called when/if "promise" resolves
* @param onRejected called when/if "promise" rejects
*/
then<U>(onFulfilled?: (value: T) => U, onRejected?: (error: any) => PromiseLike<U>): Promise<U>;
/**
* onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects.
* Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called.
* Both callbacks have a single parameter , the fulfillment value or rejection reason.
* "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve.
* If an error is thrown in the callback, the returned promise rejects with that error.
* @param onFulfilled called when/if "promise" resolves
* @param onRejected called when/if "promise" rejects
*/
then<U>(onFulfilled?: (value: T) => U, onRejected?: (error: any) => U): Promise<U>;
/**
* onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects.
* Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called.
* Both callbacks have a single parameter , the fulfillment value or rejection reason.
* "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve.
* If an error is thrown in the callback, the returned promise rejects with that error.
* @param onFulfilled called when/if "promise" resolves
* @param onRejected called when/if "promise" rejects
*/
then<U>(onFulfilled?: (value: T) => U, onRejected?: (error: any) => void): Promise<U>;
/**
* Sugar for promise.then(undefined, onRejected)
* @param onRejected called when/if "promise" rejects
*/
catch<U>(onRejected?: (error: any) => PromiseLike<U>): Promise<U>;
/**
* Sugar for promise.then(undefined, onRejected)
* @param onRejected called when/if "promise" rejects
*/
catch<U>(onRejected?: (error: any) => U): Promise<U>;
/**
* Sugar for promise.then(undefined, onRejected)
* @param onRejected called when/if "promise" rejects
*/
catch<U>(onRejected?: (error: any) => void): Promise<U>;
}
interface PromiseConstructor {
/**
* A reference to the prototype.
*/
prototype: Promise<any>;
/**
* Creates a new Promise.
* @param executor A callback used to initialize the promise. This callback is passed two arguments:
* a resolve callback used resolve the promise with a value or the result of another promise,
* and a reject callback used to reject the promise with a provided reason or error.
*/
new <T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
/**
* Returns promise (only if promise.constructor == Promise)
*/
cast<T>(promise: Promise<T>): Promise<T>;
/**
* Make a promise that fulfills to obj.
*/
cast<T>(object: T): Promise<T>;
/**
* Make a new promise from the PromiseLike.
* A promise-like can be anything as far as it has a "then" method.
* This also creates a new promise if you pass it a genuine JavaScript promise, making it less efficient for casting than Promise.cast.
*/
resolve<T>(promise?: PromiseLike<T>): Promise<T>;
/**
* Make a promise that fulfills to obj. Same as Promise.cast(obj) in this situation.
*/
resolve<T>(object?: T): Promise<T>;
/**
* Make a promise that rejects to obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error
*/
reject(error: any): Promise<any>;
/**
* Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects.
* the array passed to all can be a mixture of promise-like objects and other objects.
* The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value.
*/
all<T>(promises: Promise<T>[]): Promise<T[]>;
/**
* Make a Promise that fulfills when any item fulfills, and rejects if any item rejects.
*/
race<T>(promises: Promise<T>[]): Promise<T>;
}
declare var Promise: PromiseConstructor;