|
2 | 2 | * Represents the completion of an asynchronous operation
|
3 | 3 | */
|
4 | 4 | interface Promise<T> {
|
| 5 | + /** |
| 6 | + * Creates a new Promise with the same internal state of this Promise. |
| 7 | + * @returns A Promise. |
| 8 | + */ |
| 9 | + then(): Promise<T>; |
| 10 | + |
| 11 | + /** |
| 12 | + * Attaches callbacks for the resolution and/or rejection of the Promise. |
| 13 | + * @param onfulfilled The callback to execute when the Promise is resolved. |
| 14 | + * @returns A Promise for the completion of which ever callback is executed. |
| 15 | + */ |
| 16 | + then(onfulfilled: undefined | null): Promise<T>; |
| 17 | + |
| 18 | + /** |
| 19 | + * Attaches callbacks for the resolution and/or rejection of the Promise. |
| 20 | + * @param onfulfilled The callback to execute when the Promise is resolved. |
| 21 | + * @returns A Promise for the completion of which ever callback is executed. |
| 22 | + */ |
| 23 | + then<TResult>(onfulfilled: (value: T) => TResult | PromiseLike<TResult>): Promise<TResult>; |
| 24 | + |
5 | 25 | /**
|
6 | 26 | * Attaches callbacks for the resolution and/or rejection of the Promise.
|
7 | 27 | * @param onfulfilled The callback to execute when the Promise is resolved.
|
8 | 28 | * @param onrejected The callback to execute when the Promise is rejected.
|
9 | 29 | * @returns A Promise for the completion of which ever callback is executed.
|
10 | 30 | */
|
11 |
| - then<TResult1, TResult2>(onfulfilled: (value: T) => TResult1 | PromiseLike<TResult1>, onrejected: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>; |
| 31 | + then(onfulfilled: undefined | null, onrejected: undefined | null): Promise<T>; |
| 32 | + |
| 33 | + /** |
| 34 | + * Attaches callbacks for the resolution and/or rejection of the Promise. |
| 35 | + * @param onfulfilled The callback to execute when the Promise is resolved. |
| 36 | + * @param onrejected The callback to execute when the Promise is rejected. |
| 37 | + * @returns A Promise for the completion of which ever callback is executed. |
| 38 | + */ |
| 39 | + then<TResult>(onfulfilled: undefined | null, onrejected: (reason: any) => TResult | PromiseLike<TResult>): Promise<T | TResult>; |
12 | 40 |
|
13 | 41 | /**
|
14 | 42 | * Attaches callbacks for the resolution and/or rejection of the Promise.
|
15 | 43 | * @param onfulfilled The callback to execute when the Promise is resolved.
|
16 | 44 | * @param onrejected The callback to execute when the Promise is rejected.
|
17 | 45 | * @returns A Promise for the completion of which ever callback is executed.
|
18 | 46 | */
|
19 |
| - then<TResult>(onfulfilled: (value: T) => TResult | PromiseLike<TResult>, onrejected: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>; |
| 47 | + then<TResult>(onfulfilled: (value: T) => TResult | PromiseLike<TResult>, onrejected: undefined | null): Promise<TResult>; |
20 | 48 |
|
21 | 49 | /**
|
22 | 50 | * Attaches callbacks for the resolution and/or rejection of the Promise.
|
23 | 51 | * @param onfulfilled The callback to execute when the Promise is resolved.
|
| 52 | + * @param onrejected The callback to execute when the Promise is rejected. |
24 | 53 | * @returns A Promise for the completion of which ever callback is executed.
|
25 | 54 | */
|
26 |
| - then<TResult>(onfulfilled: (value: T) => TResult | PromiseLike<TResult>): Promise<TResult>; |
| 55 | + then<TResult1, TResult2>(onfulfilled: (value: T) => TResult1 | PromiseLike<TResult1>, onrejected: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>; |
27 | 56 |
|
28 | 57 | /**
|
29 | 58 | * Creates a new Promise with the same internal state of this Promise.
|
30 | 59 | * @returns A Promise.
|
31 | 60 | */
|
32 |
| - then(): Promise<T>; |
| 61 | + catch(): Promise<T>; |
33 | 62 |
|
34 | 63 | /**
|
35 | 64 | * Attaches a callback for only the rejection of the Promise.
|
36 | 65 | * @param onrejected The callback to execute when the Promise is rejected.
|
37 | 66 | * @returns A Promise for the completion of the callback.
|
38 | 67 | */
|
39 |
| - catch<TResult>(onrejected: (reason: any) => TResult | PromiseLike<TResult>): Promise<T | TResult>; |
| 68 | + catch(onrejected: undefined | null): Promise<T>; |
40 | 69 |
|
41 | 70 | /**
|
42 | 71 | * Attaches a callback for only the rejection of the Promise.
|
43 | 72 | * @param onrejected The callback to execute when the Promise is rejected.
|
44 | 73 | * @returns A Promise for the completion of the callback.
|
45 | 74 | */
|
46 |
| - catch(onrejected: (reason: any) => T | PromiseLike<T>): Promise<T>; |
| 75 | + catch<TResult>(onrejected: (reason: any) => TResult | PromiseLike<TResult>): Promise<T | TResult>; |
47 | 76 | }
|
48 | 77 |
|
49 | 78 | interface PromiseConstructor {
|
@@ -140,6 +169,86 @@ interface PromiseConstructor {
|
140 | 169 | */
|
141 | 170 | all<T>(values: (T | PromiseLike<T>)[]): Promise<T[]>;
|
142 | 171 |
|
| 172 | + /** |
| 173 | + * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved |
| 174 | + * or rejected. |
| 175 | + * @param values An array of Promises. |
| 176 | + * @returns A new Promise. |
| 177 | + */ |
| 178 | + race<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10>; |
| 179 | + |
| 180 | + /** |
| 181 | + * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved |
| 182 | + * or rejected. |
| 183 | + * @param values An array of Promises. |
| 184 | + * @returns A new Promise. |
| 185 | + */ |
| 186 | + race<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>; |
| 187 | + |
| 188 | + /** |
| 189 | + * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved |
| 190 | + * or rejected. |
| 191 | + * @param values An array of Promises. |
| 192 | + * @returns A new Promise. |
| 193 | + */ |
| 194 | + race<T1, T2, T3, T4, T5, T6, T7, T8>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>; |
| 195 | + |
| 196 | + /** |
| 197 | + * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved |
| 198 | + * or rejected. |
| 199 | + * @param values An array of Promises. |
| 200 | + * @returns A new Promise. |
| 201 | + */ |
| 202 | + race<T1, T2, T3, T4, T5, T6, T7>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<T1 | T2 | T3 | T4 | T5 | T6 | T7>; |
| 203 | + |
| 204 | + /** |
| 205 | + * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved |
| 206 | + * or rejected. |
| 207 | + * @param values An array of Promises. |
| 208 | + * @returns A new Promise. |
| 209 | + */ |
| 210 | + race<T1, T2, T3, T4, T5, T6>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<T1 | T2 | T3 | T4 | T5 | T6>; |
| 211 | + |
| 212 | + /** |
| 213 | + * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved |
| 214 | + * or rejected. |
| 215 | + * @param values An array of Promises. |
| 216 | + * @returns A new Promise. |
| 217 | + */ |
| 218 | + race<T1, T2, T3, T4, T5>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<T1 | T2 | T3 | T4 | T5>; |
| 219 | + |
| 220 | + /** |
| 221 | + * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved |
| 222 | + * or rejected. |
| 223 | + * @param values An array of Promises. |
| 224 | + * @returns A new Promise. |
| 225 | + */ |
| 226 | + race<T1, T2, T3, T4>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<T1 | T2 | T3 | T4>; |
| 227 | + |
| 228 | + /** |
| 229 | + * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved |
| 230 | + * or rejected. |
| 231 | + * @param values An array of Promises. |
| 232 | + * @returns A new Promise. |
| 233 | + */ |
| 234 | + race<T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<T1 | T2 | T3>; |
| 235 | + |
| 236 | + /** |
| 237 | + * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved |
| 238 | + * or rejected. |
| 239 | + * @param values An array of Promises. |
| 240 | + * @returns A new Promise. |
| 241 | + */ |
| 242 | + race<T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<T1 | T2>; |
| 243 | + |
| 244 | + /** |
| 245 | + * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved |
| 246 | + * or rejected. |
| 247 | + * @param values An array of Promises. |
| 248 | + * @returns A new Promise. |
| 249 | + */ |
| 250 | + race<T>(values: (T | PromiseLike<T>)[]): Promise<T>; |
| 251 | + |
143 | 252 | /**
|
144 | 253 | * Creates a new rejected promise for the provided reason.
|
145 | 254 | * @param reason The reason the promise was rejected.
|
|
0 commit comments