-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lib/es2020): Add
Promise.allSettled(…)
(#34065)
* feat(lib/es2020): Add `Promise.allSettled(…)` * test(lib): Update tests to account for `es2020.promise` * fix(lib/es2020): `Promise.allSettled(…)` takes `Iterable` argument * refactor(lib/es2020): Rename `Promise.allSettled(…)` return type * feat(lib/es2020): Simplify `Promise.allSettled(…)` type declaration * refactor(lib/es2020): Improve naming of `Promise.allSettled(…)` types
- Loading branch information
1 parent
8939b25
commit 5a34274
Showing
5 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/// <reference lib="es2019" /> | ||
/// <reference lib="es2020.bigint" /> | ||
/// <reference lib="es2020.promise" /> | ||
/// <reference lib="es2020.string" /> | ||
/// <reference lib="es2020.symbol.wellknown" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
interface PromiseFulfilledResult<T> { | ||
status: "fulfilled"; | ||
value: T; | ||
} | ||
|
||
interface PromiseRejectedResult { | ||
status: "rejected"; | ||
reason: any; | ||
} | ||
|
||
type PromiseSettledResult<T> = PromiseFulfilledResult<T> | PromiseRejectedResult; | ||
|
||
interface PromiseConstructor { | ||
/** | ||
* Creates a Promise that is resolved with an array of results when all | ||
* of the provided Promises resolve or reject. | ||
* @param values An array of Promises. | ||
* @returns A new Promise. | ||
*/ | ||
allSettled<T extends readonly unknown[] | readonly [unknown]>(values: T): | ||
Promise<{ -readonly [P in keyof T]: PromiseSettledResult<T[P] extends PromiseLike<infer U> ? U : T[P]> }>; | ||
|
||
/** | ||
* Creates a Promise that is resolved with an array of results when all | ||
* of the provided Promises resolve or reject. | ||
* @param values An array of Promises. | ||
* @returns A new Promise. | ||
*/ | ||
allSettled<T>(values: Iterable<T>): Promise<PromiseSettledResult<T extends PromiseLike<infer U> ? U : T>[]>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters