Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Adds 'Awaited' type alias and updates to Promise.all/race/allSettled/any#45350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
rbuckton merged 4 commits intomainfromawaitedTypeAlias
Sep 10, 2021

Conversation

@rbuckton
Copy link
Contributor

This adds anAwaited<T> type alias that supports the following capabilities:

  • Recursive unwrap
  • Resolves promise-like "thenables" without relying onPromiseLike (to avoid issues with augmentation/assignability)
  • Non promise "thenables" resolve tonever
  • Supportsnull andundefined in non-strictNullChecks mode
  • Relies on recursion limiters to provide errors for unresolvable promises.

This also adds overloads toPromise.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

strelga, ExE-Boss, shine1594, iugo, kiprasmel, AlexeyMz, mhdahman, SlurpTheo, stefee, jsejcksn, and 11 more reacted with thumbs up emojipaul-marechal, ggoodman, r3nanp, rojvv, and astatochek reacted with heart emojitonivj5, sindresorhus, treybrisbane, strelga, ExE-Boss, MattiasBuelens, VladSez, kiprasmel, stefee, jsejcksn, and 6 more reacted with rocket emoji
@rbuckton
Copy link
ContributorAuthor

@typescript-bot perf test
@typescript-bot run dt
@typescript-bot test this
@typescript-bot user test this

@typescript-bot
Copy link
Collaborator

typescript-bot commentedAug 25, 2021
edited
Loading

Heya@rbuckton, I've started to run the parallelized Definitely Typed test suite on this PR at46ce88c. You can monitor the buildhere.

@typescript-bot
Copy link
Collaborator

typescript-bot commentedAug 25, 2021
edited
Loading

Heya@rbuckton, I've started to run the perf test suite on this PR at46ce88c. You can monitor the buildhere.

Update:The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commentedAug 25, 2021
edited
Loading

Heya@rbuckton, I've started to run the parallelized community code test suite on this PR at46ce88c. You can monitor the buildhere.

@typescript-bot
Copy link
Collaborator

typescript-bot commentedAug 25, 2021
edited
Loading

Heya@rbuckton, I've started to run the extended test suite on this PR at46ce88c. You can monitor the buildhere.

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished andfailed. I've opened aPR with the baseline diff from master.

@rbuckton
Copy link
ContributorAuthor

Interesting outcomes from the rwc tests:

  • firebase.log:Cannot find module 'firebase' or its corresponding type declarations. - Probably not due to this change...
  • chrome-devtools-frontend.log: 4 errors go away, one error changes from:
    node_modules/chrome-devtools-frontend/front_end/elements/ComputedStyleWidget.js(91,34):   error TS2339: Property 'spread' does not exist on type 'Promise<[any, any, any, any, any, any, any, any, any, any]>'.
    to
    node_modules/chrome-devtools-frontend/front_end/elements/ComputedStyleWidget.js(91,34):   error TS2339: Property 'spread' does not exist on type 'Promise<(CSSMatchedStyles | ComputedStyle)[]>'.
  • prettier.log: OOM. Not sure if this is because of this change or something else, I'll investigate.

@typescript-bot
Copy link
Collaborator

@rbuckton
The results of the perf run you requested are in!

Here they are:

Comparison Report - main..45350

Metricmain45350DeltaBestWorst
Angular - node (v10.16.3, x64)
Memory used351,106k (± 0.02%)351,322k (± 0.02%)+216k (+ 0.06%)351,198k351,601k
Parse Time1.92s (± 1.88%)1.92s (± 1.43%)-0.00s (- 0.10%)1.88s2.02s
Bind Time0.87s (± 0.89%)0.85s (± 0.47%)-0.02s (- 2.30%)0.84s0.86s
Check Time5.40s (± 0.48%)5.38s (± 0.36%)-0.02s (- 0.33%)5.33s5.42s
Emit Time5.86s (± 0.50%)5.84s (± 0.77%)-0.01s (- 0.20%)5.77s5.99s
Total Time14.04s (± 0.40%)13.99s (± 0.38%)-0.05s (- 0.38%)13.91s14.11s
Compiler-Unions - node (v10.16.3, x64)
Memory used203,794k (± 0.39%)203,415k (± 0.04%)-379k (- 0.19%)203,242k203,540k
Parse Time0.78s (± 1.04%)0.79s (± 0.74%)+0.00s (+ 0.51%)0.78s0.80s
Bind Time0.53s (± 1.14%)0.53s (± 0.94%)+0.00s (+ 0.19%)0.52s0.54s
Check Time7.84s (± 0.57%)7.78s (± 0.40%)-0.06s (- 0.75%)7.71s7.84s
Emit Time2.44s (± 0.39%)2.43s (± 0.92%)-0.01s (- 0.25%)2.39s2.49s
Total Time11.59s (± 0.41%)11.52s (± 0.32%)-0.07s (- 0.59%)11.41s11.58s
Monaco - node (v10.16.3, x64)
Memory used340,673k (± 0.02%)340,553k (± 0.02%)-120k (- 0.04%)340,442k340,717k
Parse Time1.46s (± 1.20%)1.45s (± 1.83%)-0.01s (- 0.34%)1.40s1.54s
Bind Time0.74s (± 0.95%)0.75s (± 0.80%)+0.00s (+ 0.67%)0.74s0.76s
Check Time5.42s (± 0.46%)5.38s (± 0.47%)-0.04s (- 0.72%)5.30s5.42s
Emit Time3.13s (± 0.66%)3.14s (± 0.93%)+0.01s (+ 0.29%)3.09s3.23s
Total Time10.75s (± 0.42%)10.71s (± 0.38%)-0.03s (- 0.31%)10.60s10.82s
TFS - node (v10.16.3, x64)
Memory used304,064k (± 0.03%)303,921k (± 0.02%)-144k (- 0.05%)303,768k304,064k
Parse Time1.19s (± 0.97%)1.19s (± 1.22%)0.00s ( 0.00%)1.17s1.24s
Bind Time0.71s (± 0.56%)0.71s (± 1.13%)-0.00s (- 0.42%)0.69s0.72s
Check Time4.89s (± 0.45%)4.92s (± 0.42%)+0.02s (+ 0.47%)4.85s4.95s
Emit Time3.32s (± 1.40%)3.35s (± 1.44%)+0.03s (+ 0.81%)3.24s3.43s
Total Time10.11s (± 0.46%)10.16s (± 0.58%)+0.05s (+ 0.47%)10.01s10.26s
material-ui - node (v10.16.3, x64)
Memory used469,701k (± 0.01%)469,821k (± 0.01%)+119k (+ 0.03%)469,691k469,935k
Parse Time1.74s (± 2.11%)1.74s (± 2.12%)+0.00s (+ 0.23%)1.71s1.89s
Bind Time0.67s (± 0.60%)0.66s (± 0.79%)-0.01s (- 1.49%)0.65s0.67s
Check Time14.13s (± 0.35%)14.17s (± 0.90%)+0.04s (+ 0.30%)13.97s14.62s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time16.54s (± 0.31%)16.57s (± 0.80%)+0.03s (+ 0.21%)16.33s17.02s
Angular - node (v12.1.0, x64)
Memory used329,162k (± 0.03%)329,233k (± 0.03%)+70k (+ 0.02%)328,933k329,428k
Parse Time1.90s (± 0.65%)1.88s (± 0.35%)-0.02s (- 0.89%)1.87s1.90s
Bind Time0.86s (± 0.43%)0.84s (± 0.95%)-0.02s (- 2.66%)0.83s0.87s
Check Time5.28s (± 0.50%)5.21s (± 0.52%)-0.07s (- 1.25%)5.16s5.25s
Emit Time6.14s (± 0.84%)6.08s (± 0.74%)-0.05s (- 0.86%)6.01s6.23s
Total Time14.18s (± 0.58%)14.02s (± 0.33%)-0.16s (- 1.14%)13.93s14.12s
Compiler-Unions - node (v12.1.0, x64)
Memory used190,778k (± 0.15%)190,835k (± 0.08%)+57k (+ 0.03%)190,279k191,083k
Parse Time0.78s (± 0.57%)0.78s (± 1.00%)-0.00s (- 0.38%)0.77s0.80s
Bind Time0.54s (± 0.68%)0.54s (± 0.68%)+0.00s (+ 0.00%)0.53s0.54s
Check Time7.37s (± 0.83%)7.31s (± 0.54%)-0.07s (- 0.90%)7.22s7.38s
Emit Time2.45s (± 0.77%)2.43s (± 1.10%)-0.02s (- 0.61%)2.40s2.52s
Total Time11.14s (± 0.62%)11.05s (± 0.56%)-0.08s (- 0.75%)10.96s11.23s
Monaco - node (v12.1.0, x64)
Memory used323,773k (± 0.01%)323,740k (± 0.02%)-33k (- 0.01%)323,615k323,923k
Parse Time1.43s (± 0.66%)1.42s (± 0.65%)-0.01s (- 0.56%)1.40s1.44s
Bind Time0.73s (± 0.91%)0.72s (± 0.92%)-0.01s (- 1.37%)0.71s0.74s
Check Time5.30s (± 0.51%)5.29s (± 0.51%)-0.01s (- 0.21%)5.22s5.34s
Emit Time3.21s (± 0.49%)3.21s (± 0.98%)+0.00s (+ 0.09%)3.17s3.33s
Total Time10.67s (± 0.39%)10.64s (± 0.45%)-0.03s (- 0.24%)10.52s10.74s
TFS - node (v12.1.0, x64)
Memory used288,800k (± 0.02%)288,745k (± 0.02%)-54k (- 0.02%)288,639k288,842k
Parse Time1.21s (± 0.90%)1.20s (± 1.05%)-0.01s (- 0.99%)1.17s1.23s
Bind Time0.70s (± 1.07%)0.70s (± 0.68%)0.00s ( 0.00%)0.69s0.71s
Check Time4.85s (± 0.45%)4.84s (± 0.69%)-0.01s (- 0.21%)4.75s4.91s
Emit Time3.37s (± 1.20%)3.34s (± 1.12%)-0.03s (- 0.80%)3.25s3.44s
Total Time10.13s (± 0.51%)10.08s (± 0.65%)-0.05s (- 0.51%)9.87s10.23s
material-ui - node (v12.1.0, x64)
Memory used448,530k (± 0.02%)448,571k (± 0.01%)+41k (+ 0.01%)448,412k448,653k
Parse Time1.74s (± 0.51%)1.72s (± 0.35%)-0.02s (- 1.21%)1.70s1.73s
Bind Time0.65s (± 1.16%)0.65s (± 0.95%)-0.00s (- 0.46%)0.64s0.66s
Check Time12.91s (± 0.47%)12.77s (± 0.56%)-0.14s (- 1.09%)12.62s12.92s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.30s (± 0.36%)15.13s (± 0.49%)-0.16s (- 1.08%)14.98s15.30s
Angular - node (v14.15.1, x64)
Memory used327,782k (± 0.00%)327,831k (± 0.01%)+50k (+ 0.02%)327,780k327,867k
Parse Time1.92s (± 0.51%)1.89s (± 0.37%)-0.03s (- 1.61%)1.88s1.91s
Bind Time0.91s (± 0.77%)0.87s (± 0.60%)🟩-0.04s (- 4.39%)0.86s0.88s
Check Time5.33s (± 0.48%)5.26s (± 0.53%)-0.07s (- 1.37%)5.21s5.31s
Emit Time6.26s (± 0.63%)6.14s (± 0.81%)-0.11s (- 1.81%)6.06s6.28s
Total Time14.42s (± 0.51%)14.17s (± 0.52%)-0.25s (- 1.75%)14.06s14.33s
Compiler-Unions - node (v14.15.1, x64)
Memory used190,432k (± 0.51%)191,428k (± 0.60%)+996k (+ 0.52%)189,517k192,746k
Parse Time0.81s (± 0.61%)0.81s (± 0.74%)-0.00s (- 0.12%)0.80s0.82s
Bind Time0.57s (± 0.60%)0.56s (± 0.59%)-0.01s (- 1.23%)0.55s0.57s
Check Time7.55s (± 0.86%)7.47s (± 0.58%)-0.07s (- 0.98%)7.38s7.55s
Emit Time2.44s (± 0.75%)2.42s (± 0.56%)-0.02s (- 0.90%)2.39s2.44s
Total Time11.36s (± 0.58%)11.26s (± 0.36%)-0.10s (- 0.90%)11.18s11.34s
Monaco - node (v14.15.1, x64)
Memory used322,558k (± 0.00%)322,512k (± 0.00%)-46k (- 0.01%)322,473k322,541k
Parse Time1.49s (± 0.45%)1.49s (± 0.69%)-0.00s (- 0.27%)1.47s1.51s
Bind Time0.75s (± 0.65%)0.75s (± 0.63%)-0.00s (- 0.13%)0.75s0.77s
Check Time5.21s (± 0.44%)5.22s (± 0.50%)+0.01s (+ 0.15%)5.17s5.28s
Emit Time3.25s (± 0.73%)3.21s (± 0.72%)-0.03s (- 1.05%)3.15s3.26s
Total Time10.71s (± 0.28%)10.68s (± 0.35%)-0.03s (- 0.30%)10.60s10.77s
TFS - node (v14.15.1, x64)
Memory used287,718k (± 0.01%)287,650k (± 0.00%)-68k (- 0.02%)287,619k287,673k
Parse Time1.25s (± 1.84%)1.25s (± 1.51%)-0.00s (- 0.32%)1.21s1.29s
Bind Time0.74s (± 4.38%)0.73s (± 3.53%)-0.01s (- 1.89%)0.71s0.83s
Check Time4.88s (± 0.60%)4.85s (± 0.47%)-0.03s (- 0.53%)4.81s4.90s
Emit Time3.47s (± 0.77%)3.47s (± 0.83%)-0.00s (- 0.03%)3.41s3.55s
Total Time10.34s (± 0.57%)10.29s (± 0.49%)-0.05s (- 0.44%)10.21s10.48s
material-ui - node (v14.15.1, x64)
Memory used446,826k (± 0.03%)446,952k (± 0.00%)+125k (+ 0.03%)446,915k447,000k
Parse Time1.76s (± 0.40%)1.76s (± 0.61%)0.00s ( 0.00%)1.73s1.78s
Bind Time0.69s (± 0.43%)0.69s (± 0.83%)+0.00s (+ 0.29%)0.68s0.70s
Check Time12.92s (± 0.33%)12.94s (± 0.59%)+0.02s (+ 0.16%)12.79s13.11s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.37s (± 0.30%)15.39s (± 0.48%)+0.03s (+ 0.17%)15.24s15.55s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory11 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
BenchmarkNameIterations
Current4535010
Baselinemain10

Developer Information:

Download Benchmark

@rbuckton
Copy link
ContributorAuthor

The OOM in Prettier doesn't seem to be related to this change, as I'm seeing it in other unrelated PRs as well.

@rbuckton
Copy link
ContributorAuthor

rbuckton commentedAug 30, 2021
edited
Loading

Notes from design meeting:

  • Need to see what this breaks.
    • Nothing seems broken in the RWC and User tests as is.
  • Need to see if we can remove overloads.
    • I'm concerned that removing overloads forall will be a breaking change for anyone who has previously used
      explicit type arguments to overcome inference issues that this will ostensibly solve. The question is whether
      this is an acceptable breaking change.
  • Maybe see if this can be leveraged byawait?
    • I am exploring this in a separate PR that I will post shortly. This is likely to be a very breaking change in higher-order, sinceawait PT wherePT is aPromise<T> andT is a type variable will now produce anAwaited<T> instead ofT. While this is arguably more correct (which was the case in theawaited T PR), it is also likely to be a breaking change.
ExE-Boss reacted with thumbs up emoji

@rbucktonrbuckton mentioned this pull requestSep 3, 2021
@rbuckton
Copy link
ContributorAuthor

I investigated whether havingawait returnAwaited<T> would be a major breaking change in#45701 and it doesn't seem like that's the case, so I will merge the changes into this PR.

@rbuckton
Copy link
ContributorAuthor

@typescript-bot perf test
@typescript-bot run dt
@typescript-bot test this
@typescript-bot user test this inline

@typescript-bot
Copy link
Collaborator

typescript-bot commentedSep 3, 2021
edited
Loading

Heya@rbuckton, I've started to run the extended test suite on this PR at657f0a9. You can monitor the buildhere.

@typescript-bot
Copy link
Collaborator

typescript-bot commentedSep 9, 2021
edited
Loading

Hey@andrewbranch, I've packed this intoan installable tgz. You can install it for testing by referencing it in yourpackage.json like so:

{    "devDependencies": {        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/110116/artifacts?artifactName=tgz&fileId=5F4D80343FB179768C7E7C97F73DA5C030AF4A59CDF0E108FC50B64AF7E7121F02&fileName=/typescript-4.5.0-insiders.20210909.tgz"    }}

and then runningnpm install.


There is also a playgroundfor this build and annpm module you can use via"typescript": "npm:@typescript-deploys/pr-build@4.5.0-pr-45350-27".;

Comment on lines +1453 to +1454
T :// argument was not an object
T;// non-thenable
Copy link
Contributor

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.

Copy link
ContributorAuthor

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.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Fixed by#45918

@frigus02
Copy link
Contributor

If anyone in the community heavily usesawait with generics and/orPromise.all, please give the above build a try and let me know your experience.

I did a quick search forPromise.all usages in the Google code base internally and only found a handful (~10) of usages with more than 1 generic parameter. We should be fine here.

To check usages ofawait with generics we will have to actually upgrade TypeScript and see where the builds break, I think. We'll probably report that together with other findings.

andrewbranch and ExE-Boss reacted with thumbs up emoji

@julienavert
Copy link

Hello everyone,

Not sure if this is the correct place to bring this up but theAwaited<T> type as-is broke our build after upgrading from typescript 4.4.3 to 4.5.2.

For reference, here is whatAwaited<T> looks like:

/** * Recursively unwraps the "awaited type" of a type. Non-promise "thenables" should resolve to `never`. This emulates the behavior of `await`. */typeAwaited<T>=Textendsnull|undefined ?T :// special case for `null | undefined` when not in `--strictNullChecks` modeTextendsobject&{then(onfulfilled: inferF):any} ?// `await` only unwraps object types with a callable `then`. Non-object types are not unwrappedFextends((value: inferV)=>any) ?// if the argument to `then` is callable, extracts the argumentAwaited<V> :// recursively unwrap the valuenever :// the argument to `then` was not callableT;// non-object or non-thenable

The problem is that we have a custom Promise class (AbortablePromise) and itsthen function accepts aonfulfilled callback that do not exactly match the conditionF extends ((value: infer V) => any).

Ourthen is declared like this:

publicthen<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>;

Soonfulfilled in our case is(value: T, abortController: AbortController) => TResult1 | PromiseLike<TResult1>) which does not match(value: infer V) => any

Hence,Awaited<T> whereT is anAbortablePromise always returnsnever.

Would it be possible to make the type condition more flexible inAwaited<T> to enable these promise extensions and still have the type be compatible withPromise.all,Promise.race, etc?

ExE-Boss reacted with eyes emoji

@wbt
Copy link

wbt commentedAug 10, 2022

It would be helpful to add some documentation about this on theUtility types page, not just in the 4.5 release notes that aren't part of the docs search.

andrewbranch, jameskerr, and bachchanvinh reacted with thumbs up emoji

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

Reviewers

@andrewbranchandrewbranchandrewbranch approved these changes

@DanielRosenwasserDanielRosenwasserAwaiting requested review from DanielRosenwasser

@weswighamweswighamAwaiting requested review from weswigham

@ahejlsbergahejlsbergAwaiting requested review from ahejlsberg

+1 more reviewer

@ExE-BossExE-BossExE-Boss left review comments

Reviewers whose approvals may not affect merge requirements

Labels

Author: TeamFor Milestone BugPRs that fix a bug with a specific milestone

Projects

Archived in project

Milestone

No milestone

10 participants

@rbuckton@typescript-bot@andrewbranch@frigus02@julienavert@wbt@ExE-Boss@weswigham@ahejlsberg

[8]ページ先頭

©2009-2025 Movatter.jp