Skip to content

Treat void-typed properties as optional - #40823

Closed
Ron Buckton (rbuckton) wants to merge 1 commit into
mainfrom
optionalVoidProperties
Closed

Treat void-typed properties as optional#40823
Ron Buckton (rbuckton) wants to merge 1 commit into
mainfrom
optionalVoidProperties

Conversation

@rbuckton

Copy link
Copy Markdown
Contributor

This treats void-typed properties (or properties with a void constituent) as optional for the purpose of assignability. This is similar to how we treat trailing void parameters in signatures. The primary intended use case is to address an ECMAScript spec-compliance issue with IteratorResult, though this has possibly further-reaching consequences than just that change:

// giveninterfaceIteratorYieldResult<TYield>{done?: false;value: TYield;}interfaceIteratorReturnResult<TReturn>{done: true;value: TReturn;}typeIteratorResult<T,TReturn=any>=IteratorYieldResult<T>|IteratorReturnResult<TReturn>;constmyIterator: Iterator<number,void>={next(value?: number){return{done: true};// `value` is not required because it is typed `void`.}}

Unfortunately, simply making value optional isn't an option as it would make the result of yield* essentially always optional, as well as the result from calling .next() when iteration has completed. For example:

function*g()/*: Generator<never, number, undefined> */{return1;}function*f(){constx=yield*g();// x should be `number`, but if `value` is optional it is `number | undefined`.}constresult=g().next();// IteratorResult<never, number>;if(result.done){result;// IteratorReturnResult<number>;result.value;// should be `number`, but if `value` is optional it is `number | undefined`.}

I did consider changing the type of IteratorResult:

interfaceIteratorYieldResult<TYield>{done?: false;value: TYield;}interfaceIteratorReturnResult<TReturn>{done: true;value: TReturn;}interfaceIteratorVoidReturnResult{done: true;value?: void;}typeIteratorResult<T,TReturn=any>=|IteratorYieldResult<T>|IteratorReturnResult<TReturn>|(TReturnextendsvoid ? IteratorVoidReturnResult : never);

However that would require adding additional complexity to getIterationTypesOfIteratorResult to extract iteration types, and I'm also concerned that changing IteratorResult in this way would cause issues with assignability for existing custom iterators.

Fixes#38479

@rbuckton

Copy link
Copy Markdown
ContributorAuthor

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 29, 2020

Copy link
Copy Markdown
Contributor

Heya Ron Buckton (@rbuckton), I've started to run the parallelized Definitely Typed test suite on this PR at be9b85d. You can monitor the build here.

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 29, 2020

Copy link
Copy Markdown
Contributor

Heya Ron Buckton (@rbuckton), I've started to run the parallelized community code test suite on this PR at be9b85d. You can monitor the build here.

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 29, 2020

Copy link
Copy Markdown
Contributor

Heya Ron Buckton (@rbuckton), I've started to run the extended test suite on this PR at be9b85d. You can monitor the build here.

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 29, 2020

Copy link
Copy Markdown
Contributor

Heya Ron Buckton (@rbuckton), I've started to run the perf test suite on this PR at be9b85d. You can monitor the build here.

Update: The results are in!

@typescript-bot

Copy link
Copy Markdown
Contributor

Ron Buckton (@rbuckton)
The results of the perf run you requested are in!

Here they are:

Comparison Report - master..40823

Metricmaster40823DeltaBestWorst
Angular - node (v10.16.3, x64)
Memory used349,616k (± 0.01%)349,665k (± 0.03%)+49k (+ 0.01%)349,497k349,945k
Parse Time2.00s (± 0.26%)2.01s (± 0.42%)+0.01s (+ 0.50%)1.98s2.02s
Bind Time0.82s (± 0.81%)0.82s (± 0.91%)0.00s ( 0.00%)0.81s0.85s
Check Time4.90s (± 0.77%)4.89s (± 0.49%)-0.01s (- 0.16%)4.85s4.96s
Emit Time5.19s (± 0.52%)5.17s (± 0.51%)-0.02s (- 0.35%)5.09s5.22s
Total Time12.91s (± 0.43%)12.90s (± 0.33%)-0.01s (- 0.11%)12.81s13.00s
Monaco - node (v10.16.3, x64)
Memory used354,341k (± 0.03%)354,311k (± 0.02%)-30k (- 0.01%)354,162k354,413k
Parse Time1.56s (± 0.52%)1.56s (± 0.51%)-0.00s (- 0.13%)1.54s1.58s
Bind Time0.71s (± 0.52%)0.71s (± 0.69%)-0.00s (- 0.14%)0.70s0.72s
Check Time5.07s (± 0.61%)5.06s (± 0.50%)-0.01s (- 0.14%)4.99s5.12s
Emit Time2.76s (± 0.86%)2.75s (± 0.59%)-0.01s (- 0.43%)2.72s2.79s
Total Time10.10s (± 0.49%)10.08s (± 0.22%)-0.02s (- 0.23%)10.03s10.13s
TFS - node (v10.16.3, x64)
Memory used307,541k (± 0.04%)307,560k (± 0.02%)+19k (+ 0.01%)307,429k307,667k
Parse Time1.21s (± 0.56%)1.21s (± 0.49%)0.00s ( 0.00%)1.20s1.22s
Bind Time0.67s (± 0.99%)0.67s (± 1.21%)-0.00s (- 0.45%)0.64s0.68s
Check Time4.54s (± 0.49%)4.54s (± 0.46%)-0.00s (- 0.07%)4.48s4.58s
Emit Time2.90s (± 1.00%)2.92s (± 0.81%)+0.02s (+ 0.62%)2.85s2.97s
Total Time9.33s (± 0.46%)9.34s (± 0.47%)+0.01s (+ 0.12%)9.21s9.41s
material-ui - node (v10.16.3, x64)
Memory used489,001k (± 0.01%)488,962k (± 0.01%)-39k (- 0.01%)488,898k489,067k
Parse Time1.98s (± 0.45%)1.98s (± 0.69%)-0.00s (- 0.10%)1.96s2.02s
Bind Time0.65s (± 0.86%)0.65s (± 0.53%)-0.00s (- 0.15%)0.64s0.65s
Check Time13.50s (± 0.78%)13.59s (± 0.66%)+0.09s (+ 0.64%)13.32s13.73s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time16.14s (± 0.64%)16.22s (± 0.60%)+0.08s (+ 0.50%)15.93s16.38s
Angular - node (v12.1.0, x64)
Memory used326,839k (± 0.03%)326,684k (± 0.09%)-155k (- 0.05%)325,639k327,041k
Parse Time1.99s (± 0.51%)1.99s (± 0.61%)+0.00s (+ 0.15%)1.97s2.03s
Bind Time0.81s (± 0.64%)0.81s (± 0.45%)-0.00s (- 0.37%)0.80s0.81s
Check Time4.80s (± 0.57%)4.79s (± 0.40%)-0.01s (- 0.19%)4.75s4.84s
Emit Time5.36s (± 0.68%)5.35s (± 0.82%)-0.00s (- 0.04%)5.29s5.51s
Total Time12.95s (± 0.46%)12.94s (± 0.46%)-0.01s (- 0.08%)12.85s13.15s
Monaco - node (v12.1.0, x64)
Memory used336,492k (± 0.01%)336,509k (± 0.03%)+18k (+ 0.01%)336,355k336,697k
Parse Time1.54s (± 0.86%)1.54s (± 0.84%)-0.00s (- 0.13%)1.51s1.57s
Bind Time0.70s (± 1.84%)0.69s (± 0.32%)-0.01s (- 1.29%)0.69s0.70s
Check Time4.87s (± 0.47%)4.87s (± 0.51%)+0.00s (+ 0.08%)4.83s4.92s
Emit Time2.83s (± 0.76%)2.81s (± 0.81%)-0.02s (- 0.67%)2.77s2.88s
Total Time9.93s (± 0.47%)9.91s (± 0.38%)-0.03s (- 0.26%)9.84s10.03s
TFS - node (v12.1.0, x64)
Memory used291,819k (± 0.02%)291,850k (± 0.02%)+31k (+ 0.01%)291,708k291,960k
Parse Time1.23s (± 0.66%)1.23s (± 0.59%)-0.00s (- 0.16%)1.22s1.25s
Bind Time0.64s (± 0.90%)0.65s (± 1.15%)+0.00s (+ 0.62%)0.64s0.67s
Check Time4.44s (± 0.36%)4.45s (± 0.45%)+0.01s (+ 0.16%)4.40s4.50s
Emit Time2.94s (± 0.96%)2.93s (± 0.75%)-0.00s (- 0.07%)2.90s2.98s
Total Time9.25s (± 0.42%)9.26s (± 0.34%)+0.01s (+ 0.12%)9.18s9.31s
material-ui - node (v12.1.0, x64)
Memory used466,976k (± 0.05%)466,897k (± 0.05%)-78k (- 0.02%)466,019k467,077k
Parse Time2.00s (± 0.38%)2.00s (± 0.35%)-0.00s (- 0.15%)1.99s2.02s
Bind Time0.64s (± 0.58%)0.64s (± 0.81%)+0.00s (+ 0.63%)0.63s0.65s
Check Time12.01s (± 0.69%)12.12s (± 0.66%)+0.11s (+ 0.93%)12.00s12.28s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time14.65s (± 0.59%)14.76s (± 0.60%)+0.11s (+ 0.76%)14.62s14.94s
Angular - node (v8.9.0, x64)
Memory used346,316k (± 0.02%)346,375k (± 0.03%)+59k (+ 0.02%)346,082k346,566k
Parse Time2.55s (± 0.37%)2.55s (± 0.29%)+0.01s (+ 0.20%)2.54s2.57s
Bind Time0.86s (± 0.58%)0.87s (± 1.17%)+0.00s (+ 0.46%)0.85s0.90s
Check Time5.54s (± 0.73%)5.55s (± 0.46%)+0.01s (+ 0.16%)5.48s5.59s
Emit Time6.21s (± 1.36%)6.13s (± 1.42%)-0.09s (- 1.38%)5.92s6.34s
Total Time15.17s (± 0.51%)15.09s (± 0.55%)-0.07s (- 0.47%)14.86s15.31s
Monaco - node (v8.9.0, x64)
Memory used355,579k (± 0.02%)355,628k (± 0.01%)+50k (+ 0.01%)355,564k355,690k
Parse Time1.90s (± 0.44%)1.89s (± 0.47%)-0.01s (- 0.47%)1.87s1.91s
Bind Time0.89s (± 0.82%)0.90s (± 0.67%)+0.00s (+ 0.34%)0.88s0.91s
Check Time5.62s (± 0.55%)5.60s (± 0.57%)-0.01s (- 0.25%)5.50s5.67s
Emit Time3.31s (± 1.50%)3.31s (± 1.15%)+0.00s (+ 0.12%)3.19s3.36s
Total Time11.71s (± 0.55%)11.70s (± 0.58%)-0.01s (- 0.12%)11.50s11.80s
TFS - node (v8.9.0, x64)
Memory used309,276k (± 0.01%)309,310k (± 0.01%)+34k (+ 0.01%)309,218k309,401k
Parse Time1.56s (± 0.32%)1.55s (± 0.54%)-0.01s (- 0.45%)1.54s1.58s
Bind Time0.68s (± 0.95%)0.68s (± 0.86%)-0.00s (- 0.15%)0.66s0.69s
Check Time5.30s (± 0.59%)5.29s (± 0.37%)-0.00s (- 0.08%)5.25s5.33s
Emit Time2.93s (± 0.80%)2.93s (± 0.48%)-0.00s (- 0.14%)2.90s2.95s
Total Time10.46s (± 0.28%)10.45s (± 0.21%)-0.02s (- 0.14%)10.38s10.48s
material-ui - node (v8.9.0, x64)
Memory used493,347k (± 0.02%)493,314k (± 0.01%)-33k (- 0.01%)493,128k493,459k
Parse Time2.40s (± 0.36%)2.40s (± 0.44%)+0.00s (+ 0.04%)2.38s2.43s
Bind Time0.81s (± 1.17%)0.82s (± 0.71%)+0.00s (+ 0.37%)0.80s0.83s
Check Time17.92s (± 0.84%)18.09s (± 0.92%)+0.17s (+ 0.97%)17.67s18.42s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time21.14s (± 0.68%)21.32s (± 0.77%)+0.18s (+ 0.85%)20.89s21.65s
Angular - node (v8.9.0, x86)
Memory used198,593k (± 0.02%)198,625k (± 0.02%)+32k (+ 0.02%)198,529k198,736k
Parse Time2.48s (± 0.81%)2.47s (± 0.43%)-0.01s (- 0.44%)2.44s2.49s
Bind Time1.00s (± 0.93%)1.00s (± 1.15%)+0.00s (+ 0.50%)0.97s1.03s
Check Time4.99s (± 0.61%)5.00s (± 0.43%)+0.01s (+ 0.14%)4.95s5.05s
Emit Time5.92s (± 0.90%)5.93s (± 1.24%)+0.01s (+ 0.17%)5.80s6.14s
Total Time14.39s (± 0.56%)14.40s (± 0.47%)+0.01s (+ 0.08%)14.23s14.57s
Monaco - node (v8.9.0, x86)
Memory used201,394k (± 0.01%)201,381k (± 0.02%)-13k (- 0.01%)201,277k201,437k
Parse Time1.93s (± 0.81%)1.93s (± 0.69%)-0.00s (- 0.21%)1.90s1.96s
Bind Time0.71s (± 0.91%)0.71s (± 0.78%)0.00s ( 0.00%)0.70s0.72s
Check Time5.46s (± 1.24%)5.50s (± 1.37%)+0.04s (+ 0.79%)5.38s5.68s
Emit Time3.03s (± 3.23%)2.97s (± 3.51%)-0.06s (- 1.91%)2.65s3.08s
Total Time11.13s (± 0.64%)11.10s (± 0.71%)-0.02s (- 0.22%)10.92s11.30s
TFS - node (v8.9.0, x86)
Memory used176,811k (± 0.02%)176,806k (± 0.03%)-5k (- 0.00%)176,732k176,961k
Parse Time1.58s (± 0.84%)1.58s (± 0.53%)-0.00s (- 0.13%)1.57s1.60s
Bind Time0.65s (± 1.23%)0.64s (± 0.90%)-0.01s (- 0.77%)0.63s0.66s
Check Time4.79s (± 0.56%)4.78s (± 0.65%)-0.00s (- 0.10%)4.73s4.85s
Emit Time2.80s (± 1.10%)2.79s (± 1.14%)-0.01s (- 0.36%)2.73s2.90s
Total Time9.82s (± 0.40%)9.80s (± 0.47%)-0.02s (- 0.17%)9.71s9.88s
material-ui - node (v8.9.0, x86)
Memory used277,775k (± 0.01%)277,740k (± 0.02%)-35k (- 0.01%)277,637k277,879k
Parse Time2.46s (± 0.82%)2.46s (± 0.54%)-0.00s (- 0.04%)2.43s2.50s
Bind Time0.71s (± 5.86%)0.74s (± 7.55%)+0.02s (+ 3.51%)0.67s0.87s
Check Time16.38s (± 0.69%)16.55s (± 0.74%)+0.17s (+ 1.01%)16.37s16.92s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time19.55s (± 0.74%)19.74s (± 0.69%)+0.19s (+ 0.96%)19.48s20.07s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-166-generic
Architecturex64
Available Memory16 GB
Available Memory1 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v8.9.0, x64)
  • node (v8.9.0, x86)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v8.9.0, x64)
  • Angular - node (v8.9.0, x86)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v8.9.0, x64)
  • Monaco - node (v8.9.0, x86)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v8.9.0, x64)
  • TFS - node (v8.9.0, x86)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v8.9.0, x64)
  • material-ui - node (v8.9.0, x86)
BenchmarkNameIterations
Current4082310
Baselinemaster10

@typescript-bot

Copy link
Copy Markdown
Contributor

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@sandersn

Copy link
Copy Markdown
Member

Ron Buckton (@rbuckton) where did we land on this? I remember discussing something like this in the design meeting, but not whether we decided to go forward with it.

@sandersn

Copy link
Copy Markdown
Member

Ron Buckton (@rbuckton) do you mind if I close this until we come up with a comprehensive reform of void? At least, my memory of our last discussion of this is that we're kind of stuck on this particular change. I might be mis-remembering, though.

@weswigham
Wesley Wigham (weswigham) removed their request for review March 4, 2022 19:21
@sandersn

Copy link
Copy Markdown
Member

Closing this for now.

@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
@jakebailey
Jake Bailey (jakebailey) deleted the optionalVoidProperties branch August 28, 2026 19:35
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

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

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

IteratorResult<T> definition conflicts with the JS spec

3 participants

@rbuckton@typescript-bot@sandersn