Skip to content

feat(lib/es2020): Add Promise.allSettled(…) - #34065

Merged
Daniel Rosenwasser (DanielRosenwasser) merged 7 commits into
microsoft:masterfrom
ExE-Boss:lib/es2020/add-promise-allsettled
Jan 3, 2020
Merged

Daniel Rosenwasser (DanielRosenwasser) merged 7 commits into
microsoft:masterfrom
ExE-Boss:lib/es2020/add-promise-allsettled

Conversation

@ExE-Boss

@ExE-Boss ExE Boss (ExE-Boss) commented Oct 12, 2019 •

Copy link
Copy Markdown
Contributor

Depends on #33707 (I’ve now inlined the Awaited<T> type)


Fixes #31083
Closes #31085


review?(Wenlu Wang (@Kingwl))

Comment thread src/lib/es2020.promise.d.ts Resolved

@Kingwl Wenlu Wang (Kingwl) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@trmaphi

Copy link
Copy Markdown

LGTM

@graup

Copy link
Copy Markdown

I guess this code can be simplified similarly to #33707 ?

@SimonSchick

Copy link
Copy Markdown
Contributor

Nope, typings for node still need to support 2.1 until further notice.

@ExE-Boss

Copy link
Copy Markdown
Contributor Author

I first need #33707 to be merged, so that I can get access to the Awaited<T> type.

Comment thread src/lib/es2020.promise.d.ts Resolved
Comment thread src/lib/es2020.promise.d.ts Outdated
* @param values An array of Promises.
* @returns A new Promise.
*/
allSettled<T extends readonly any[] | readonly [any]>(values: T): Promise<{ -readonly [P in keyof T]: PromiseSettledResult<T[P] extends PromiseLike<infer U> ? U : T[P]> }>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make these readonly unknown[] | readonly [unknown]? (Ryan Cavanaugh (@RyanCavanaugh) Ron Buckton (@rbuckton))

Comment thread src/lib/es2020.promise.d.ts Outdated
@@ -0,0 +1,29 @@
interface PromiseResolvedResult<T> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. Drive-by code review here. Shouldn’t this be named something like PromiseFulfilledResult to adhere to the states and fates terminology? I think the reason calling it PromiseResolvedResult is incorrect here is that while all fulfilled promises are resolved, not all resolved promises are fulfilled. A promise can be resolved to a pending promise, in which case it has not settled, and it can also be resolved to a rejected promise, in which case it has not fulfilled.

If my interpretation of states and fates terminology is correct, shouldn’t the correct name of this interface be PromiseFulfilledResult?

@ExE-Boss
ExE Boss (ExE-Boss) force-pushed the lib/es2020/add-promise-allsettled branch from ec3628c to 2929aad Compare January 2, 2020 17:01
@DanielRosenwasser

Copy link
Copy Markdown
Member

Thank you!

@ExE-Boss
ExE Boss (ExE-Boss) deleted the lib/es2020/add-promise-allsettled branch January 3, 2020 21:03
@SimonSchick

Copy link
Copy Markdown
Contributor

Still feel like it should've used unknown for better type safety 🤷‍♂

@sanglt1902

Copy link
Copy Markdown

LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet