1/*! *****************************************************************************
2Copyright (c) Microsoft Corporation. All rights reserved.
3Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4this file except in compliance with the License. You may obtain a copy of the
5License at http://www.apache.org/licenses/LICENSE-2.0
6
7THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10MERCHANTABLITY OR NON-INFRINGEMENT.
11
12See the Apache Version 2.0 License for specific language governing permissions
13and limitations under the License.
14***************************************************************************** */
15
16
17
18/// <reference no-default-lib="true"/>
19
20
21interface PromiseConstructor {
22    /**
23     * A reference to the prototype.
24     */
25    readonly prototype: Promise<any>;
26
27    /**
28     * Creates a new Promise.
29     * @param executor A callback used to initialize the promise. This callback is passed two arguments:
30     * a resolve callback used to resolve the promise with a value or the result of another promise,
31     * and a reject callback used to reject the promise with a provided reason or error.
32     */
33    new <T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
34
35    /**
36     * Creates a Promise that is resolved with an array of results when all of the provided Promises
37     * resolve, or rejected when any Promise is rejected.
38     * @param values An array of Promises.
39     * @returns A new Promise.
40     */
41    all<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: readonly [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]>;
42
43    /**
44     * Creates a Promise that is resolved with an array of results when all of the provided Promises
45     * resolve, or rejected when any Promise is rejected.
46     * @param values An array of Promises.
47     * @returns A new Promise.
48     */
49    all<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: readonly [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]>;
50
51    /**
52     * Creates a Promise that is resolved with an array of results when all of the provided Promises
53     * resolve, or rejected when any Promise is rejected.
54     * @param values An array of Promises.
55     * @returns A new Promise.
56     */
57    all<T1, T2, T3, T4, T5, T6, T7, T8>(values: readonly [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]>;
58
59    /**
60     * Creates a Promise that is resolved with an array of results when all of the provided Promises
61     * resolve, or rejected when any Promise is rejected.
62     * @param values An array of Promises.
63     * @returns A new Promise.
64     */
65    all<T1, T2, T3, T4, T5, T6, T7>(values: readonly [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]>;
66
67    /**
68     * Creates a Promise that is resolved with an array of results when all of the provided Promises
69     * resolve, or rejected when any Promise is rejected.
70     * @param values An array of Promises.
71     * @returns A new Promise.
72     */
73    all<T1, T2, T3, T4, T5, T6>(values: readonly [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]>;
74
75    /**
76     * Creates a Promise that is resolved with an array of results when all of the provided Promises
77     * resolve, or rejected when any Promise is rejected.
78     * @param values An array of Promises.
79     * @returns A new Promise.
80     */
81    all<T1, T2, T3, T4, T5>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>;
82
83    /**
84     * Creates a Promise that is resolved with an array of results when all of the provided Promises
85     * resolve, or rejected when any Promise is rejected.
86     * @param values An array of Promises.
87     * @returns A new Promise.
88     */
89    all<T1, T2, T3, T4>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[T1, T2, T3, T4]>;
90
91    /**
92     * Creates a Promise that is resolved with an array of results when all of the provided Promises
93     * resolve, or rejected when any Promise is rejected.
94     * @param values An array of Promises.
95     * @returns A new Promise.
96     */
97    all<T1, T2, T3>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>;
98
99    /**
100     * Creates a Promise that is resolved with an array of results when all of the provided Promises
101     * resolve, or rejected when any Promise is rejected.
102     * @param values An array of Promises.
103     * @returns A new Promise.
104     */
105    all<T1, T2>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
106
107    /**
108     * Creates a Promise that is resolved with an array of results when all of the provided Promises
109     * resolve, or rejected when any Promise is rejected.
110     * @param values An array of Promises.
111     * @returns A new Promise.
112     */
113    all<T>(values: readonly (T | PromiseLike<T>)[]): Promise<T[]>;
114
115    // see: lib.es2015.iterable.d.ts
116    // all<T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>;
117
118    /**
119     * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
120     * or rejected.
121     * @param values An array of Promises.
122     * @returns A new Promise.
123     */
124    race<T>(values: readonly T[]): Promise<T extends PromiseLike<infer U> ? U : T>;
125
126    // see: lib.es2015.iterable.d.ts
127    // race<T>(values: Iterable<T>): Promise<T extends PromiseLike<infer U> ? U : T>;
128
129    /**
130     * Creates a new rejected promise for the provided reason.
131     * @param reason The reason the promise was rejected.
132     * @returns A new rejected Promise.
133     */
134    reject<T = never>(reason?: any): Promise<T>;
135
136    /**
137     * Creates a new resolved promise.
138     * @returns A resolved promise.
139     */
140    resolve(): Promise<void>;
141
142    /**
143     * Creates a new resolved promise for the provided value.
144     * @param value A promise.
145     * @returns A promise whose internal state matches the provided promise.
146     */
147    resolve<T>(value: T | PromiseLike<T>): Promise<T>;
148}
149
150declare var Promise: PromiseConstructor;
151