• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1interface PromiseConstructor {
2    /**
3     * A reference to the prototype.
4     */
5    readonly prototype: Promise<any>;
6
7    /**
8     * Creates a new Promise.
9     * @param executor A callback used to initialize the promise. This callback is passed two arguments:
10     * a resolve callback used to resolve the promise with a value or the result of another promise,
11     * and a reject callback used to reject the promise with a provided reason or error.
12     */
13    new <T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
14
15    /**
16     * Creates a Promise that is resolved with an array of results when all of the provided Promises
17     * resolve, or rejected when any Promise is rejected.
18     * @param values An array of Promises.
19     * @returns A new Promise.
20     */
21    all<T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]> }>;
22
23    // see: lib.es2015.iterable.d.ts
24    // all<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>;
25
26    /**
27     * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
28     * or rejected.
29     * @param values An array of Promises.
30     * @returns A new Promise.
31     */
32    race<T extends readonly unknown[] | []>(values: T): Promise<Awaited<T[number]>>;
33
34    // see: lib.es2015.iterable.d.ts
35    // race<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>;
36
37    /**
38     * Creates a new rejected promise for the provided reason.
39     * @param reason The reason the promise was rejected.
40     * @returns A new rejected Promise.
41     */
42    reject<T = never>(reason?: any): Promise<T>;
43
44    /**
45     * Creates a new resolved promise.
46     * @returns A resolved promise.
47     */
48    resolve(): Promise<void>;
49    /**
50     * Creates a new resolved promise for the provided value.
51     * @param value A promise.
52     * @returns A promise whose internal state matches the provided promise.
53     */
54    resolve<T>(value: T): Promise<Awaited<T>>;
55    /**
56     * Creates a new resolved promise for the provided value.
57     * @param value A promise.
58     * @returns A promise whose internal state matches the provided promise.
59     */
60    resolve<T>(value: T | PromiseLike<T>): Promise<Awaited<T>>;
61}
62
63declare var Promise: PromiseConstructor;
64