Interface PromiseConstructor
new PromiseConstructor<T>(
executor: (
resolve: (value: T | PromiseLike<T>) => void,
reject: (reason?: any) => void,
) => void,
): Promise<T>;
"[species]": PromiseConstructor;
prototype: Promise<any>;
all<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>;
all<T extends [] | readonly unknown[]>(
values: T,
): Promise<{ -readonly [P in string | number | symbol]: Awaited<T[P<P>]> }>;
allSettled<T extends [] | readonly unknown[]>(
values: T,
): Promise<
{
-readonly [P in string
| number
| symbol]: PromiseSettledResult<Awaited<T[P<P>]>>
},
>;
allSettled<T>(
values: Iterable<T | PromiseLike<T>>,
): Promise<PromiseSettledResult<Awaited<T>>[]>;
any<T extends [] | readonly unknown[]>(
values: T,
): Promise<Awaited<T[number]>>;
any<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>;
race<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>;
race<T extends [] | readonly unknown[]>(
values: T,
): Promise<Awaited<T[number]>>;
reject<T = never>(reason?: any): Promise<T>;
resolve(): Promise<void>;
resolve<T>(value: T): Promise<Awaited<T>>;
resolve<T>(value: T | PromiseLike<T>): Promise<Awaited<T>>;
withResolvers<T>(): PromiseWithResolvers<T>;
}
Index
Constructors
Properties
Methods
Constructors
constructor
- new PromiseConstructor<T>(
executor: (
resolve: (value: T | PromiseLike<T>) => void,
reject: (reason?: any) => void,
) => void,
): Promise<T> Type Parameters
Parameters
- executor: (
resolve: (value: T | PromiseLike<T>) => void,
reject: (reason?: any) => void,
) => voidA callback used to initialize the promise. This callback is passed two arguments: a resolve callback used to 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.
Returns Promise<T>
- executor: (
Methods
all
- all<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>
Creates a Promise that is resolved with an array of results when all of the provided Promises resolve, or rejected when any Promise is rejected.
Type Parameters
Parameters
- values: Iterable<T | PromiseLike<T>>
An iterable of Promises.
Returns Promise<Awaited<T>[]>
A new Promise.
- values: Iterable<T | PromiseLike<T>>
- all<T extends [] | readonly unknown[]>(
values: T,
): Promise<{ -readonly [P in string | number | symbol]: Awaited<T[P<P>]> }> Creates a Promise that is resolved with an array of results when all of the provided Promises resolve, or rejected when any Promise is rejected.
Type Parameters
Parameters
- values: T
An array of Promises.
Returns Promise<{ -readonly [P in string | number | symbol]: Awaited<T[P<P>]> }>
A new Promise.
- values: T
allSettled
- allSettled<T extends [] | readonly unknown[]>(
values: T,
): Promise<
{
-readonly [P in string
| number
| symbol]: PromiseSettledResult<Awaited<T[P<P>]>>
},
> Creates a Promise that is resolved with an array of results when all of the provided Promises resolve or reject.
Type Parameters
Parameters
- values: T
An array of Promises.
Returns Promise<
{
-readonly [P in string
| number
| symbol]: PromiseSettledResult<Awaited<T[P<P>]>>
},
>A new Promise.
- values: T
- allSettled<T>(
values: Iterable<T | PromiseLike<T>>,
): Promise<PromiseSettledResult<Awaited<T>>[]> Creates a Promise that is resolved with an array of results when all of the provided Promises resolve or reject.
Type Parameters
Parameters
- values: Iterable<T | PromiseLike<T>>
An array of Promises.
Returns Promise<PromiseSettledResult<Awaited<T>>[]>
A new Promise.
- values: Iterable<T | PromiseLike<T>>
any
- any<T extends [] | readonly unknown[]>(values: T): Promise<Awaited<T[number]>>
The any function returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError containing an array of rejection reasons if all of the given promises are rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm.
Type Parameters
Parameters
- values: T
An array or iterable of Promises.
Returns Promise<Awaited<T[number]>>
A new Promise.
- values: T
- any<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>
The any function returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError containing an array of rejection reasons if all of the given promises are rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm.
Type Parameters
Parameters
- values: Iterable<T | PromiseLike<T>>
An array or iterable of Promises.
Returns Promise<Awaited<T>>
A new Promise.
- values: Iterable<T | PromiseLike<T>>
race
- race<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>
Creates a Promise that is resolved or rejected when any of the provided Promises are resolved or rejected.
Type Parameters
Parameters
- values: Iterable<T | PromiseLike<T>>
An iterable of Promises.
Returns Promise<Awaited<T>>
A new Promise.
- values: Iterable<T | PromiseLike<T>>
- race<T extends [] | readonly unknown[]>(values: T): Promise<Awaited<T[number]>>
Creates a Promise that is resolved or rejected when any of the provided Promises are resolved or rejected.
Type Parameters
Parameters
- values: T
An array of Promises.
Returns Promise<Awaited<T[number]>>
A new Promise.
- values: T
reject
resolve
- resolve(): Promise<void>
Creates a new resolved promise.
Returns Promise<void>
A resolved promise.
- resolve<T>(value: T): Promise<Awaited<T>>
Creates a new resolved promise for the provided value.
Type Parameters
Parameters
- value: T
A promise.
Returns Promise<Awaited<T>>
A promise whose internal state matches the provided promise.
- value: T
- resolve<T>(value: T | PromiseLike<T>): Promise<Awaited<T>>
Creates a new resolved promise for the provided value.
Type Parameters
Parameters
- value: T | PromiseLike<T>
A promise.
Returns Promise<Awaited<T>>
A promise whose internal state matches the provided promise.
- value: T | PromiseLike<T>
withResolvers
- withResolvers<T>(): PromiseWithResolvers<T>
Creates a new Promise and returns it in an object, along with its resolve and reject functions.
Type Parameters
Returns PromiseWithResolvers<T>
An object with the properties
promise
,resolve
, andreject
.const { promise, resolve, reject } = Promise.withResolvers<T>();
Creates a new Promise.