-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Adds 'Awaited' type alias and updates to Promise.all/race/allSettled/any #45350
Conversation
@typescript-bot perf test |
Heya @rbuckton, I've started to run the perf test suite on this PR at 46ce88c. You can monitor the build here. Update: The results are in! |
The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master. |
Interesting outcomes from the rwc tests:
|
@rbuckton Here they are:Comparison Report - main..45350
System
Hosts
Scenarios
Developer Information: |
The OOM in Prettier doesn't seem to be related to this change, as I'm seeing it in other unrelated PRs as well. |
Notes from design meeting:
|
I investigated whether having |
@typescript-bot perf test |
Heya @andrewbranch, I've started to run the tarball bundle task on this PR at 6fd4ca8. You can monitor the build here. |
Hey @andrewbranch, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
6fd4ca8
to
6703b9f
Compare
6703b9f
to
d83915c
Compare
T : // argument was not an object | ||
T; // non-thenable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that these comments are swapped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently so. I will push up a small fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by #45918
I did a quick search for To check usages of |
Hello everyone, Not sure if this is the correct place to bring this up but the For reference, here is what /**
* Recursively unwraps the "awaited type" of a type. Non-promise "thenables" should resolve to `never`. This emulates the behavior of `await`.
*/
type Awaited<T> =
T extends null | undefined ? T : // special case for `null | undefined` when not in `--strictNullChecks` mode
T extends object & { then(onfulfilled: infer F): any } ? // `await` only unwraps object types with a callable `then`. Non-object types are not unwrapped
F extends ((value: infer V) => any) ? // if the argument to `then` is callable, extracts the argument
Awaited<V> : // recursively unwrap the value
never : // the argument to `then` was not callable
T; // non-object or non-thenable The problem is that we have a custom Promise class ( Our public then<TResult1 = T, TResult2 = never>(
onfulfilled?: ((value: T, abortController: AbortController) => TResult1 | PromiseLike<TResult1>) | undefined | null,
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null
): AbortablePromise<TResult1 | TResult2>; So Hence, Would it be possible to make the type condition more flexible in |
It would be helpful to add some documentation about this on the Utility types page, not just in the 4.5 release notes that aren't part of the docs search. |
This adds an
Awaited<T>
type alias that supports the following capabilities:PromiseLike
(to avoid issues with augmentation/assignability)never
null
andundefined
in non-strictNullChecks modeThis also adds overloads to
Promise.all
,Promise.race
,Promise.allSettled
, andPromise.any
to leverageAwaited<T>
.Supersedes #33707, thanks @jablko for your prior work on this.
Fixes #27711
Fixes #22469
Fixes #28427
Fixes #30390
Fixes #31722
Fixes #33559
Fixes #33562
Fixes #33752
Fixes #34924
Fixes #34937
Fixes #35136
Fixes #35258