GeezerVison is showing github.com — Control flow analysis for destructured discriminated unions by ahejlsberg · Pull Request #46266 · microsoft/TypeScript
Conversation
This PR implements control flow analysis for dependent parameters and variables declared by destructuring discriminated unions. Specifically, when non-rest binding elements are declared as const variables or const-like parameters (parameters for which there are no assignments in the function body) and the parent type for the destructuring is a discriminated union type, conditional checks for variables destructured from discriminant properties now affect the types of other variables declared in the same destructuring.
Some examples:
type Action =
| { kind: 'A', payload: number }
| { kind: 'B', payload: string };
function f10({ kind, payload }: Action) {
if (kind === 'A') {
payload.toFixed();
}
if (kind === 'B') {
payload.toUpperCase();
}
}
function f11(action: Action) {
const { kind, payload } = action;
if (kind === 'A') {
payload.toFixed();
}
if (kind === 'B') {
payload.toUpperCase();
}
}
function f12({ kind, payload }: Action) {
switch (kind) {
case 'A':
payload.toFixed();
break;
case 'B':
payload.toUpperCase();
break;
default:
payload; // never
}
}
function f13(it: Iterator<number>) {
const { value, done } = it.next();
if (!done) {
value; // number
}
}
Fixes #10830.
Fixes #35283.
Fixes #38020.
Fixes #46143.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
andrewbranch, DanielRosenwasser, orta, tzachbon, agentcooper, tonivj5, vincentbel, callmeberzerker, ushironoko, petamoriken, and 252 more reacted with thumbs up emoji
andrewbranch, DanielRosenwasser, orta, tzachbon, tonivj5, treybrisbane, callmeberzerker, ushironoko, vlad-zhukov, yukiyokotani, and 148 more reacted with hooray emoji
andrewbranch, DanielRosenwasser, orta, tzachbon, tonivj5, callmeberzerker, ushironoko, okunokentaro, uhyo, finnmerlett, and 172 more reacted with heart emoji
andrewbranch, DanielRosenwasser, orta, AviVahl, tzachbon, tonivj5, uhyo, finnmerlett, yoshkosh, futurGH, and 86 more reacted with rocket emoji
tjjfvi, worstpractice, vivshaw, lxsmnsyc, adithwip, DoctorJohn, brainkim, phase, Xetera, samuela, and 20 more reacted with eyes emoji
All reactions
-
👍
262 reactions
-
🎉
158 reactions
-
❤️
182 reactions
-
🚀
96 reactions
-
👀
30 reactions
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Daniel Rosenwasser (@DanielRosenwasser)
The results of the perf run you requested are in!
Here they are:
Comparison Report - main..46266
| Metric |
main |
46266 |
Delta |
Best |
Worst |
| Angular - node (v10.16.3, x64) |
| Memory used |
354,215k (± 0.03%) |
354,186k (± 0.01%) |
-29k (- 0.01%) |
354,087k |
354,305k |
| Parse Time |
1.96s (± 0.53%) |
1.96s (± 0.71%) |
+0.00s (+ 0.05%) |
1.93s |
1.99s |
| Bind Time |
0.84s (± 0.95%) |
0.84s (± 0.90%) |
+0.01s (+ 0.84%) |
0.83s |
0.86s |
| Check Time |
5.46s (± 0.35%) |
5.48s (± 0.45%) |
+0.03s (+ 0.48%) |
5.45s |
5.56s |
| Emit Time |
5.87s (± 0.62%) |
5.86s (± 0.57%) |
-0.00s (- 0.05%) |
5.79s |
5.97s |
| Total Time |
14.12s (± 0.27%) |
14.16s (± 0.36%) |
+0.04s (+ 0.25%) |
14.05s |
14.27s |
| Compiler-Unions - node (v10.16.3, x64) |
| Memory used |
203,893k (± 0.03%) |
203,892k (± 0.02%) |
-1k (- 0.00%) |
203,797k |
203,997k |
| Parse Time |
0.78s (± 0.63%) |
0.79s (± 0.84%) |
+0.01s (+ 1.15%) |
0.78s |
0.81s |
| Bind Time |
0.52s (± 1.19%) |
0.52s (± 1.39%) |
+0.00s (+ 0.58%) |
0.51s |
0.54s |
| Check Time |
7.88s (± 0.53%) |
7.96s (± 0.90%) |
+0.08s (+ 1.05%) |
7.79s |
8.15s |
| Emit Time |
2.44s (± 1.14%) |
2.45s (± 0.70%) |
+0.01s (+ 0.33%) |
2.42s |
2.50s |
| Total Time |
11.63s (± 0.46%) |
11.73s (± 0.58%) |
+0.10s (+ 0.89%) |
11.56s |
11.91s |
| Monaco - node (v10.16.3, x64) |
| Memory used |
342,126k (± 0.03%) |
342,090k (± 0.02%) |
-36k (- 0.01%) |
341,983k |
342,353k |
| Parse Time |
1.48s (± 0.58%) |
1.48s (± 0.73%) |
-0.00s (- 0.20%) |
1.45s |
1.50s |
| Bind Time |
0.74s (± 0.64%) |
0.75s (± 0.30%) |
+0.01s (+ 0.81%) |
0.74s |
0.75s |
| Check Time |
5.44s (± 0.50%) |
5.46s (± 0.70%) |
+0.02s (+ 0.44%) |
5.40s |
5.56s |
| Emit Time |
3.20s (± 0.57%) |
3.16s (± 0.65%) |
-0.04s (- 1.25%) |
3.11s |
3.22s |
| Total Time |
10.87s (± 0.36%) |
10.85s (± 0.32%) |
-0.02s (- 0.14%) |
10.75s |
10.92s |
| TFS - node (v10.16.3, x64) |
| Memory used |
304,810k (± 0.02%) |
304,836k (± 0.02%) |
+26k (+ 0.01%) |
304,675k |
304,993k |
| Parse Time |
1.19s (± 0.54%) |
1.20s (± 0.72%) |
+0.01s (+ 0.84%) |
1.19s |
1.22s |
| Bind Time |
0.71s (± 0.87%) |
0.71s (± 0.87%) |
-0.00s (- 0.28%) |
0.69s |
0.72s |
| Check Time |
4.98s (± 0.49%) |
4.99s (± 0.44%) |
+0.01s (+ 0.24%) |
4.95s |
5.03s |
| Emit Time |
3.31s (± 1.01%) |
3.36s (± 1.92%) |
+0.05s (+ 1.39%) |
3.28s |
3.60s |
| Total Time |
10.20s (± 0.47%) |
10.26s (± 0.76%) |
+0.07s (+ 0.65%) |
10.13s |
10.52s |
| material-ui - node (v10.16.3, x64) |
| Memory used |
472,371k (± 0.01%) |
472,446k (± 0.02%) |
+75k (+ 0.02%) |
472,275k |
472,678k |
| Parse Time |
1.77s (± 0.38%) |
1.78s (± 0.41%) |
+0.01s (+ 0.62%) |
1.76s |
1.79s |
| Bind Time |
0.66s (± 0.79%) |
0.66s (± 0.55%) |
-0.00s (- 0.46%) |
0.65s |
0.66s |
| Check Time |
14.38s (± 0.27%) |
14.49s (± 0.66%) |
+0.11s (+ 0.74%) |
14.32s |
14.77s |
| Emit Time |
0.00s (± 0.00%) |
0.00s (± 0.00%) |
0.00s ( NaN%) |
0.00s |
0.00s |
| Total Time |
16.81s (± 0.22%) |
16.93s (± 0.59%) |
+0.12s (+ 0.68%) |
16.75s |
17.22s |
| Angular - node (v12.1.0, x64) |
| Memory used |
332,133k (± 0.02%) |
332,132k (± 0.02%) |
-1k (- 0.00%) |
332,036k |
332,241k |
| Parse Time |
1.94s (± 0.88%) |
1.96s (± 0.55%) |
+0.02s (+ 1.13%) |
1.94s |
1.98s |
| Bind Time |
0.81s (± 0.64%) |
0.83s (± 1.29%) |
+0.02s (+ 1.98%) |
0.80s |
0.86s |
| Check Time |
5.28s (± 0.29%) |
5.34s (± 0.60%) |
+0.06s (+ 1.10%) |
5.27s |
5.39s |
| Emit Time |
6.12s (± 0.83%) |
6.12s (± 0.68%) |
+0.01s (+ 0.10%) |
6.02s |
6.23s |
| Total Time |
14.15s (± 0.41%) |
14.25s (± 0.54%) |
+0.10s (+ 0.69%) |
14.07s |
14.36s |
| Compiler-Unions - node (v12.1.0, x64) |
| Memory used |
191,377k (± 0.03%) |
191,369k (± 0.08%) |
-8k (- 0.00%) |
190,745k |
191,518k |
| Parse Time |
0.78s (± 0.75%) |
0.79s (± 0.82%) |
+0.01s (+ 1.42%) |
0.77s |
0.80s |
| Bind Time |
0.53s (± 0.71%) |
0.53s (± 0.76%) |
+0.00s (+ 0.76%) |
0.52s |
0.54s |
| Check Time |
7.35s (± 0.49%) |
7.43s (± 0.57%) |
+0.08s (+ 1.09%) |
7.34s |
7.53s |
| Emit Time |
2.47s (± 0.69%) |
2.46s (± 0.77%) |
-0.00s (- 0.16%) |
2.41s |
2.50s |
| Total Time |
11.12s (± 0.42%) |
11.21s (± 0.49%) |
+0.09s (+ 0.81%) |
11.12s |
11.35s |
| Monaco - node (v12.1.0, x64) |
| Memory used |
325,207k (± 0.03%) |
325,124k (± 0.03%) |
-82k (- 0.03%) |
324,858k |
325,256k |
| Parse Time |
1.46s (± 0.73%) |
1.47s (± 0.56%) |
+0.00s (+ 0.07%) |
1.45s |
1.49s |
| Bind Time |
0.73s (± 0.45%) |
0.73s (± 0.76%) |
+0.00s (+ 0.27%) |
0.72s |
0.75s |
| Check Time |
5.33s (± 0.60%) |
5.34s (± 0.43%) |
+0.02s (+ 0.28%) |
5.29s |
5.38s |
| Emit Time |
3.19s (± 0.87%) |
3.19s (± 1.05%) |
+0.01s (+ 0.25%) |
3.13s |
3.28s |
| Total Time |
10.71s (± 0.48%) |
10.74s (± 0.42%) |
+0.03s (+ 0.26%) |
10.67s |
10.85s |
| TFS - node (v12.1.0, x64) |
| Memory used |
289,482k (± 0.02%) |
289,479k (± 0.02%) |
-3k (- 0.00%) |
289,379k |
289,609k |
| Parse Time |
1.21s (± 0.74%) |
1.23s (± 0.87%) |
+0.01s (+ 0.82%) |
1.21s |
1.25s |
| Bind Time |
0.69s (± 0.83%) |
0.69s (± 0.69%) |
+0.00s (+ 0.43%) |
0.68s |
0.70s |
| Check Time |
4.91s (± 0.64%) |
4.91s (± 0.30%) |
+0.01s (+ 0.14%) |
4.88s |
4.95s |
| Emit Time |
3.36s (± 0.86%) |
3.36s (± 1.15%) |
+0.00s (+ 0.06%) |
3.29s |
3.47s |
| Total Time |
10.17s (± 0.44%) |
10.19s (± 0.54%) |
+0.02s (+ 0.24%) |
10.09s |
10.32s |
| material-ui - node (v12.1.0, x64) |
| Memory used |
450,968k (± 0.05%) |
451,115k (± 0.01%) |
+147k (+ 0.03%) |
451,009k |
451,259k |
| Parse Time |
1.77s (± 0.60%) |
1.79s (± 0.71%) |
+0.01s (+ 0.79%) |
1.75s |
1.82s |
| Bind Time |
0.64s (± 0.87%) |
0.64s (± 1.18%) |
+0.00s (+ 0.47%) |
0.63s |
0.66s |
| Check Time |
12.95s (± 0.37%) |
13.11s (± 0.62%) |
+0.16s (+ 1.27%) |
12.91s |
13.30s |
| Emit Time |
0.00s (± 0.00%) |
0.00s (± 0.00%) |
0.00s ( NaN%) |
0.00s |
0.00s |
| Total Time |
15.37s (± 0.35%) |
15.55s (± 0.58%) |
+0.18s (+ 1.15%) |
15.32s |
15.74s |
| Angular - node (v14.15.1, x64) |
| Memory used |
330,493k (± 0.01%) |
330,531k (± 0.01%) |
+38k (+ 0.01%) |
330,483k |
330,588k |
| Parse Time |
1.94s (± 0.77%) |
1.95s (± 0.55%) |
+0.01s (+ 0.31%) |
1.93s |
1.98s |
| Bind Time |
0.86s (± 0.55%) |
0.86s (± 0.61%) |
+0.00s (+ 0.23%) |
0.85s |
0.87s |
| Check Time |
5.36s (± 0.69%) |
5.41s (± 0.52%) |
+0.05s (+ 0.95%) |
5.34s |
5.45s |
| Emit Time |
6.21s (± 0.84%) |
6.26s (± 0.73%) |
+0.05s (+ 0.81%) |
6.15s |
6.38s |
| Total Time |
14.37s (± 0.48%) |
14.48s (± 0.43%) |
+0.11s (+ 0.77%) |
14.30s |
14.57s |
| Compiler-Unions - node (v14.15.1, x64) |
| Memory used |
193,198k (± 0.02%) |
192,904k (± 0.37%) |
-293k (- 0.15%) |
190,010k |
193,286k |
| Parse Time |
0.80s (± 0.62%) |
0.81s (± 0.64%) |
+0.01s (+ 0.75%) |
0.80s |
0.82s |
| Bind Time |
0.55s (± 0.54%) |
0.56s (± 0.84%) |
+0.01s (+ 1.45%) |
0.55s |
0.57s |
| Check Time |
7.54s (± 0.65%) |
7.60s (± 0.77%) |
+0.06s (+ 0.85%) |
7.45s |
7.76s |
| Emit Time |
2.44s (± 0.95%) |
2.45s (± 0.47%) |
+0.01s (+ 0.53%) |
2.43s |
2.48s |
| Total Time |
11.34s (± 0.59%) |
11.42s (± 0.58%) |
+0.09s (+ 0.77%) |
11.26s |
11.59s |
| Monaco - node (v14.15.1, x64) |
| Memory used |
323,993k (± 0.01%) |
323,996k (± 0.01%) |
+4k (+ 0.00%) |
323,961k |
324,042k |
| Parse Time |
1.51s (± 0.55%) |
1.52s (± 0.53%) |
+0.01s (+ 0.86%) |
1.50s |
1.54s |
| Bind Time |
0.76s (± 0.65%) |
0.76s (± 0.58%) |
+0.01s (+ 0.79%) |
0.75s |
0.77s |
| Check Time |
5.29s (± 0.28%) |
5.34s (± 0.44%) |
+0.04s (+ 0.83%) |
5.27s |
5.40s |
| Emit Time |
3.22s (± 0.69%) |
3.24s (± 0.52%) |
+0.01s (+ 0.40%) |
3.20s |
3.27s |
| Total Time |
10.78s (± 0.30%) |
10.85s (± 0.23%) |
+0.08s (+ 0.72%) |
10.81s |
10.93s |
| TFS - node (v14.15.1, x64) |
| Memory used |
288,362k (± 0.01%) |
288,344k (± 0.01%) |
-18k (- 0.01%) |
288,291k |
288,400k |
| Parse Time |
1.23s (± 0.54%) |
1.24s (± 0.63%) |
+0.01s (+ 0.73%) |
1.22s |
1.26s |
| Bind Time |
0.73s (± 0.61%) |
0.74s (± 0.68%) |
+0.00s (+ 0.41%) |
0.72s |
0.74s |
| Check Time |
4.91s (± 0.46%) |
4.96s (± 0.43%) |
+0.05s (+ 1.08%) |
4.91s |
5.00s |
| Emit Time |
3.47s (± 0.65%) |
3.51s (± 0.79%) |
+0.04s (+ 1.24%) |
3.47s |
3.58s |
| Total Time |
10.34s (± 0.37%) |
10.44s (± 0.48%) |
+0.11s (+ 1.04%) |
10.34s |
10.57s |
| material-ui - node (v14.15.1, x64) |
| Memory used |
449,073k (± 0.08%) |
449,399k (± 0.00%) |
+326k (+ 0.07%) |
449,363k |
449,460k |
| Parse Time |
1.81s (± 0.43%) |
1.83s (± 0.32%) |
+0.02s (+ 1.38%) |
1.82s |
1.85s |
| Bind Time |
0.68s (± 0.70%) |
0.68s (± 0.53%) |
+0.01s (+ 1.03%) |
0.68s |
0.69s |
| Check Time |
13.14s (± 1.08%) |
13.32s (± 0.73%) |
+0.18s (+ 1.34%) |
13.05s |
13.53s |
| Emit Time |
0.00s (± 0.00%) |
0.00s (± 0.00%) |
0.00s ( NaN%) |
0.00s |
0.00s |
| Total Time |
15.63s (± 0.92%) |
15.84s (± 0.60%) |
+0.21s (+ 1.32%) |
15.57s |
16.03s |
System
| Machine Name | ts-ci-ubuntu |
| Platform | linux 4.4.0-210-generic |
| Architecture | x64 |
| Available Memory | 16 GB |
| Available Memory | 8 GB |
| CPUs | 4 × 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)
| Benchmark |
Name |
Iterations |
| Current |
46266 |
10 |
| Baseline |
main |
10 |
Developer Information:Download Benchmark
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
const declaration = symbol.valueDeclaration;
|
|
|
if (declaration && isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && declaration.parent.elements.length >= 2) {
|
|
|
const parent = declaration.parent.parent;
|
|
|
if (parent.kind === SyntaxKind.VariableDeclaration && getCombinedNodeFlags(declaration) && NodeFlags.Const || parent.kind === SyntaxKind.Parameter) {
|
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.
Small typo here:
|
if (parent.kind === SyntaxKind.VariableDeclaration && getCombinedNodeFlags(declaration) && NodeFlags.Const || parent.kind === SyntaxKind.Parameter) { |
|
if (parent.kind === SyntaxKind.VariableDeclaration && getCombinedNodeFlags(declaration) & NodeFlags.Const || parent.kind === SyntaxKind.Parameter) { |
|
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
andrewbranch, jakiestfu, severb, byjokese, zhirzh, harunurhan, keshav2010, itsMapleLeaf, worstpractice, and omril1 reacted with eyes emoji
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
usumoio, jakiestfu, throbbinjack, chancebrilz, zhirzh, ThomasBower, AlexMold, nickytonline, keshav2010, worstpractice, and 4 more reacted with rocket emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Anders Hejlsberg (@ahejlsberg)
The results of the perf run you requested are in!
Here they are:
Comparison Report - main..46266
| Metric |
main |
46266 |
Delta |
Best |
Worst |
| Angular - node (v10.16.3, x64) |
| Memory used |
354,210k (± 0.02%) |
354,233k (± 0.02%) |
+24k (+ 0.01%) |
354,043k |
354,385k |
| Parse Time |
1.95s (± 0.34%) |
1.94s (± 0.43%) |
-0.00s (- 0.10%) |
1.93s |
1.97s |
| Bind Time |
0.84s (± 1.00%) |
0.84s (± 0.58%) |
+0.00s (+ 0.36%) |
0.83s |
0.85s |
| Check Time |
5.45s (± 0.31%) |
5.47s (± 0.35%) |
+0.02s (+ 0.44%) |
5.43s |
5.51s |
| Emit Time |
5.85s (± 0.43%) |
5.85s (± 0.76%) |
-0.00s (- 0.07%) |
5.76s |
5.97s |
| Total Time |
14.09s (± 0.19%) |
14.11s (± 0.47%) |
+0.02s (+ 0.15%) |
13.96s |
14.30s |
| Compiler-Unions - node (v10.16.3, x64) |
| Memory used |
203,833k (± 0.04%) |
203,809k (± 0.04%) |
-24k (- 0.01%) |
203,681k |
204,026k |
| Parse Time |
0.79s (± 0.71%) |
0.79s (± 0.98%) |
+0.00s (+ 0.13%) |
0.77s |
0.80s |
| Bind Time |
0.52s (± 1.54%) |
0.52s (± 1.56%) |
+0.01s (+ 0.97%) |
0.50s |
0.54s |
| Check Time |
7.87s (± 0.57%) |
7.95s (± 0.68%) |
+0.08s (+ 0.95%) |
7.82s |
8.04s |
| Emit Time |
2.45s (± 1.43%) |
2.46s (± 1.10%) |
+0.01s (+ 0.45%) |
2.41s |
2.52s |
| Total Time |
11.64s (± 0.53%) |
11.72s (± 0.58%) |
+0.09s (+ 0.74%) |
11.59s |
11.83s |
| Monaco - node (v10.16.3, x64) |
| Memory used |
342,076k (± 0.02%) |
342,109k (± 0.03%) |
+33k (+ 0.01%) |
341,936k |
342,287k |
| Parse Time |
1.49s (± 0.24%) |
1.48s (± 0.61%) |
-0.01s (- 0.47%) |
1.45s |
1.49s |
| Bind Time |
0.75s (± 0.66%) |
0.75s (± 0.64%) |
+0.00s (+ 0.13%) |
0.73s |
0.75s |
| Check Time |
5.44s (± 0.79%) |
5.46s (± 0.67%) |
+0.02s (+ 0.42%) |
5.34s |
5.52s |
| Emit Time |
3.17s (± 0.59%) |
3.18s (± 1.10%) |
+0.01s (+ 0.28%) |
3.08s |
3.25s |
| Total Time |
10.84s (± 0.30%) |
10.86s (± 0.45%) |
+0.02s (+ 0.22%) |
10.70s |
10.93s |
| TFS - node (v10.16.3, x64) |
| Memory used |
304,778k (± 0.02%) |
304,852k (± 0.02%) |
+73k (+ 0.02%) |
304,693k |
304,958k |
| Parse Time |
1.20s (± 0.54%) |
1.20s (± 1.06%) |
+0.00s (+ 0.33%) |
1.18s |
1.23s |
| Bind Time |
0.71s (± 1.31%) |
0.71s (± 0.81%) |
+0.00s (+ 0.71%) |
0.70s |
0.73s |
| Check Time |
4.97s (± 0.54%) |
5.02s (± 0.36%) |
+0.05s (+ 0.97%) |
4.98s |
5.06s |
| Emit Time |
3.32s (± 1.15%) |
3.32s (± 0.76%) |
+0.01s (+ 0.18%) |
3.27s |
3.40s |
| Total Time |
10.19s (± 0.47%) |
10.25s (± 0.36%) |
+0.06s (+ 0.61%) |
10.16s |
10.35s |
| material-ui - node (v10.16.3, x64) |
| Memory used |
472,372k (± 0.02%) |
472,383k (± 0.01%) |
+11k (+ 0.00%) |
472,258k |
472,497k |
| Parse Time |
1.77s (± 0.55%) |
1.77s (± 0.65%) |
+0.00s (+ 0.06%) |
1.75s |
1.80s |
| Bind Time |
0.65s (± 0.56%) |
0.66s (± 0.87%) |
+0.01s (+ 1.38%) |
0.65s |
0.68s |
| Check Time |
14.41s (± 0.32%) |
14.52s (± 0.44%) |
+0.10s (+ 0.69%) |
14.36s |
14.68s |
| Emit Time |
0.00s (± 0.00%) |
0.00s (± 0.00%) |
0.00s ( NaN%) |
0.00s |
0.00s |
| Total Time |
16.84s (± 0.28%) |
16.95s (± 0.40%) |
+0.11s (+ 0.65%) |
16.80s |
17.12s |
| Angular - node (v12.1.0, x64) |
| Memory used |
332,068k (± 0.02%) |
332,158k (± 0.02%) |
+90k (+ 0.03%) |
331,986k |
332,291k |
| Parse Time |
1.94s (± 0.80%) |
1.95s (± 0.75%) |
+0.01s (+ 0.67%) |
1.92s |
2.00s |
| Bind Time |
0.82s (± 0.82%) |
0.82s (± 0.60%) |
-0.00s (- 0.12%) |
0.81s |
0.83s |
| Check Time |
5.28s (± 0.41%) |
5.33s (± 0.51%) |
+0.05s (+ 0.87%) |
5.27s |
5.39s |
| Emit Time |
6.10s (± 0.55%) |
6.17s (± 1.04%) |
+0.07s (+ 1.18%) |
6.03s |
6.35s |
| Total Time |
14.13s (± 0.36%) |
14.26s (± 0.60%) |
+0.13s (+ 0.91%) |
14.06s |
14.45s |
| Compiler-Unions - node (v12.1.0, x64) |
| Memory used |
191,388k (± 0.04%) |
191,346k (± 0.09%) |
-42k (- 0.02%) |
190,687k |
191,554k |
| Parse Time |
0.78s (± 0.93%) |
0.78s (± 0.85%) |
+0.00s (+ 0.13%) |
0.77s |
0.80s |
| Bind Time |
0.53s (± 1.27%) |
0.53s (± 1.25%) |
+0.01s (+ 1.14%) |
0.52s |
0.55s |
| Check Time |
7.36s (± 0.84%) |
7.45s (± 0.47%) |
+0.10s (+ 1.29%) |
7.39s |
7.55s |
| Emit Time |
2.45s (± 0.73%) |
2.46s (± 0.85%) |
+0.00s (+ 0.16%) |
2.41s |
2.51s |
| Total Time |
11.12s (± 0.65%) |
11.23s (± 0.29%) |
+0.11s (+ 0.94%) |
11.16s |
11.29s |
| Monaco - node (v12.1.0, x64) |
| Memory used |
325,154k (± 0.02%) |
325,110k (± 0.06%) |
-44k (- 0.01%) |
324,311k |
325,313k |
| Parse Time |
1.46s (± 0.65%) |
1.48s (± 0.71%) |
+0.01s (+ 0.82%) |
1.46s |
1.50s |
| Bind Time |
0.72s (± 0.50%) |
0.73s (± 0.61%) |
+0.00s (+ 0.55%) |
0.72s |
0.74s |
| Check Time |
5.34s (± 0.28%) |
5.38s (± 0.48%) |
+0.03s (+ 0.62%) |
5.31s |
5.42s |
| Emit Time |
3.20s (± 0.39%) |
3.20s (± 1.40%) |
+0.00s (+ 0.09%) |
3.14s |
3.34s |
| Total Time |
10.73s (± 0.15%) |
10.79s (± 0.49%) |
+0.05s (+ 0.49%) |
10.72s |
10.97s |
| TFS - node (v12.1.0, x64) |
| Memory used |
289,435k (± 0.02%) |
289,512k (± 0.01%) |
+77k (+ 0.03%) |
289,449k |
289,621k |
| Parse Time |
1.22s (± 0.96%) |
1.22s (± 0.83%) |
-0.01s (- 0.49%) |
1.19s |
1.23s |
| Bind Time |
0.69s (± 0.80%) |
0.69s (± 1.09%) |
+0.00s (+ 0.43%) |
0.68s |
0.72s |
| Check Time |
4.89s (± 0.43%) |
4.95s (± 0.54%) |
+0.06s (+ 1.31%) |
4.88s |
4.99s |
| Emit Time |
3.35s (± 0.86%) |
3.39s (± 0.93%) |
+0.04s (+ 1.22%) |
3.32s |
3.46s |
| Total Time |
10.15s (± 0.43%) |
10.25s (± 0.51%) |
+0.10s (+ 0.99%) |
10.14s |
10.38s |
| material-ui - node (v12.1.0, x64) |
| Memory used |
451,082k (± 0.02%) |
451,118k (± 0.02%) |
+36k (+ 0.01%) |
450,953k |
451,256k |
| Parse Time |
1.78s (± 0.53%) |
1.78s (± 0.67%) |
+0.00s (+ 0.17%) |
1.75s |
1.81s |
| Bind Time |
0.64s (± 1.14%) |
0.65s (± 1.39%) |
+0.01s (+ 1.10%) |
0.63s |
0.67s |
| Check Time |
12.95s (± 0.57%) |
13.06s (± 0.55%) |
+0.11s (+ 0.83%) |
12.92s |
13.28s |
| Emit Time |
0.00s (± 0.00%) |
0.00s (± 0.00%) |
0.00s ( NaN%) |
0.00s |
0.00s |
| Total Time |
15.37s (± 0.47%) |
15.49s (± 0.52%) |
+0.12s (+ 0.78%) |
15.32s |
15.73s |
| Angular - node (v14.15.1, x64) |
| Memory used |
330,505k (± 0.00%) |
330,510k (± 0.00%) |
+6k (+ 0.00%) |
330,485k |
330,541k |
| Parse Time |
1.94s (± 0.56%) |
1.95s (± 0.76%) |
+0.01s (+ 0.62%) |
1.92s |
1.99s |
| Bind Time |
0.86s (± 0.87%) |
0.86s (± 0.67%) |
+0.00s (+ 0.35%) |
0.85s |
0.87s |
| Check Time |
5.34s (± 0.44%) |
5.40s (± 0.37%) |
+0.05s (+ 1.01%) |
5.35s |
5.44s |
| Emit Time |
6.17s (± 0.69%) |
6.22s (± 0.72%) |
+0.05s (+ 0.78%) |
6.14s |
6.36s |
| Total Time |
14.31s (± 0.39%) |
14.43s (± 0.39%) |
+0.12s (+ 0.82%) |
14.32s |
14.59s |
| Compiler-Unions - node (v14.15.1, x64) |
| Memory used |
192,887k (± 0.37%) |
192,859k (± 0.36%) |
-28k (- 0.01%) |
190,053k |
193,271k |
| Parse Time |
0.81s (± 0.45%) |
0.81s (± 0.71%) |
+0.00s (+ 0.50%) |
0.80s |
0.83s |
| Bind Time |
0.55s (± 0.66%) |
0.56s (± 1.03%) |
+0.01s (+ 1.08%) |
0.55s |
0.57s |
| Check Time |
7.53s (± 0.56%) |
7.59s (± 0.58%) |
+0.06s (+ 0.76%) |
7.51s |
7.70s |
| Emit Time |
2.46s (± 0.92%) |
2.47s (± 0.95%) |
+0.01s (+ 0.33%) |
2.41s |
2.52s |
| Total Time |
11.35s (± 0.48%) |
11.43s (± 0.48%) |
+0.08s (+ 0.66%) |
11.29s |
11.57s |
| Monaco - node (v14.15.1, x64) |
| Memory used |
324,019k (± 0.00%) |
324,007k (± 0.01%) |
-11k (- 0.00%) |
323,961k |
324,051k |
| Parse Time |
1.50s (± 0.35%) |
1.51s (± 0.85%) |
+0.01s (+ 0.47%) |
1.49s |
1.55s |
| Bind Time |
0.76s (± 0.48%) |
0.76s (± 1.11%) |
+0.00s (+ 0.40%) |
0.75s |
0.79s |
| Check Time |
5.31s (± 0.63%) |
5.32s (± 0.46%) |
+0.01s (+ 0.17%) |
5.26s |
5.37s |
| Emit Time |
3.21s (± 0.89%) |
3.24s (± 0.69%) |
+0.03s (+ 0.97%) |
3.19s |
3.28s |
| Total Time |
10.79s (± 0.51%) |
10.83s (± 0.45%) |
+0.05s (+ 0.44%) |
10.71s |
10.91s |
| TFS - node (v14.15.1, x64) |
| Memory used |
288,348k (± 0.01%) |
288,347k (± 0.00%) |
-1k (- 0.00%) |
288,322k |
288,362k |
| Parse Time |
1.24s (± 0.52%) |
1.23s (± 0.50%) |
-0.01s (- 0.73%) |
1.22s |
1.24s |
| Bind Time |
0.73s (± 0.71%) |
0.73s (± 0.41%) |
+0.00s (+ 0.14%) |
0.73s |
0.74s |
| Check Time |
4.91s (± 0.62%) |
4.94s (± 0.48%) |
+0.03s (+ 0.61%) |
4.88s |
4.99s |
| Emit Time |
3.49s (± 0.57%) |
3.48s (± 0.98%) |
-0.01s (- 0.43%) |
3.40s |
3.56s |
| Total Time |
10.37s (± 0.40%) |
10.37s (± 0.52%) |
+0.01s (+ 0.08%) |
10.26s |
10.50s |
| material-ui - node (v14.15.1, x64) |
| Memory used |
449,122k (± 0.06%) |
449,271k (± 0.06%) |
+149k (+ 0.03%) |
448,213k |
449,436k |
| Parse Time |
1.81s (± 0.48%) |
1.82s (± 0.34%) |
+0.01s (+ 0.50%) |
1.81s |
1.84s |
| Bind Time |
0.68s (± 0.85%) |
0.68s (± 0.59%) |
+0.00s (+ 0.15%) |
0.67s |
0.69s |
| Check Time |
13.16s (± 0.89%) |
13.28s (± 0.63%) |
+0.11s (+ 0.87%) |
13.10s |
13.44s |
| Emit Time |
0.00s (± 0.00%) |
0.00s (± 0.00%) |
0.00s ( NaN%) |
0.00s |
0.00s |
| Total Time |
15.65s (± 0.77%) |
15.78s (± 0.51%) |
+0.13s (+ 0.80%) |
15.59s |
15.94s |
System
| Machine Name | ts-ci-ubuntu |
| Platform | linux 4.4.0-210-generic |
| Architecture | x64 |
| Available Memory | 16 GB |
| Available Memory | 8 GB |
| CPUs | 4 × 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)
| Benchmark |
Name |
Iterations |
| Current |
46266 |
10 |
| Baseline |
main |
10 |
Developer Information:Download Benchmark
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Anders Hejlsberg (@ahejlsberg)
The results of the perf run you requested are in!
Here they are:
Comparison Report - main..46266
| Metric |
main |
46266 |
Delta |
Best |
Worst |
| Angular - node (v14.15.1, x64) |
| Memory used |
330,505k (± 0.00%) |
330,506k (± 0.00%) |
+2k (+ 0.00%) |
330,466k |
330,542k |
| Parse Time |
1.94s (± 0.56%) |
1.99s (± 5.05%) |
+0.04s (+ 2.32%) |
1.92s |
2.39s |
| Bind Time |
0.86s (± 0.87%) |
0.86s (± 0.75%) |
+0.00s (+ 0.12%) |
0.84s |
0.87s |
| Check Time |
5.34s (± 0.44%) |
5.41s (± 0.31%) |
+0.07s (+ 1.25%) |
5.37s |
5.45s |
| Emit Time |
6.17s (± 0.69%) |
6.20s (± 0.70%) |
+0.04s (+ 0.58%) |
6.11s |
6.30s |
| Total Time |
14.31s (± 0.39%) |
14.46s (± 0.75%) |
+0.15s (+ 1.04%) |
14.33s |
14.86s |
| Compiler-Unions - node (v14.15.1, x64) |
| Memory used |
192,887k (± 0.37%) |
193,207k (± 0.03%) |
+320k (+ 0.17%) |
193,084k |
193,294k |
| Parse Time |
0.81s (± 0.45%) |
0.81s (± 0.64%) |
+0.00s (+ 0.37%) |
0.80s |
0.82s |
| Bind Time |
0.55s (± 0.66%) |
0.56s (± 0.67%) |
+0.00s (+ 0.18%) |
0.55s |
0.56s |
| Check Time |
7.53s (± 0.56%) |
7.56s (± 0.73%) |
+0.03s (+ 0.40%) |
7.44s |
7.73s |
| Emit Time |
2.46s (± 0.92%) |
2.46s (± 1.16%) |
+0.01s (+ 0.33%) |
2.42s |
2.56s |
| Total Time |
11.35s (± 0.48%) |
11.39s (± 0.47%) |
+0.04s (+ 0.37%) |
11.30s |
11.54s |
| Monaco - node (v14.15.1, x64) |
| Memory used |
324,019k (± 0.00%) |
323,991k (± 0.00%) |
-28k (- 0.01%) |
323,965k |
324,031k |
| Parse Time |
1.50s (± 0.35%) |
1.51s (± 1.25%) |
+0.00s (+ 0.27%) |
1.49s |
1.58s |
| Bind Time |
0.76s (± 0.48%) |
0.76s (± 0.65%) |
-0.00s (- 0.00%) |
0.75s |
0.77s |
| Check Time |
5.31s (± 0.63%) |
5.29s (± 0.38%) |
-0.03s (- 0.51%) |
5.24s |
5.33s |
| Emit Time |
3.21s (± 0.89%) |
3.21s (± 1.03%) |
-0.00s (- 0.12%) |
3.14s |
3.28s |
| Total Time |
10.79s (± 0.51%) |
10.76s (± 0.39%) |
-0.03s (- 0.27%) |
10.66s |
10.85s |
| TFS - node (v14.15.1, x64) |
| Memory used |
288,348k (± 0.01%) |
288,341k (± 0.01%) |
-7k (- 0.00%) |
288,291k |
288,396k |
| Parse Time |
1.24s (± 0.52%) |
1.24s (± 1.07%) |
+0.00s (+ 0.16%) |
1.22s |
1.28s |
| Bind Time |
0.73s (± 0.71%) |
0.73s (± 0.93%) |
+0.00s (+ 0.41%) |
0.72s |
0.75s |
| Check Time |
4.91s (± 0.62%) |
4.92s (± 0.44%) |
+0.01s (+ 0.18%) |
4.85s |
4.95s |
| Emit Time |
3.49s (± 0.57%) |
3.47s (± 0.70%) |
-0.02s (- 0.60%) |
3.42s |
3.52s |
| Total Time |
10.37s (± 0.40%) |
10.36s (± 0.44%) |
-0.01s (- 0.09%) |
10.26s |
10.43s |
| material-ui - node (v14.15.1, x64) |
| Memory used |
449,122k (± 0.06%) |
449,323k (± 0.04%) |
+200k (+ 0.04%) |
448,607k |
449,447k |
| Parse Time |
1.81s (± 0.48%) |
1.83s (± 2.09%) |
+0.02s (+ 1.05%) |
1.79s |
1.98s |
| Bind Time |
0.68s (± 0.85%) |
0.68s (± 0.76%) |
+0.00s (+ 0.15%) |
0.67s |
0.69s |
| Check Time |
13.16s (± 0.89%) |
13.24s (± 0.97%) |
+0.08s (+ 0.60%) |
13.03s |
13.51s |
| Emit Time |
0.00s (± 0.00%) |
0.00s (± 0.00%) |
0.00s ( NaN%) |
0.00s |
0.00s |
| Total Time |
15.65s (± 0.77%) |
15.75s (± 0.78%) |
+0.10s (+ 0.63%) |
15.51s |
16.02s |
System
| Machine Name | ts-ci-ubuntu |
| Platform | linux 4.4.0-210-generic |
| Architecture | x64 |
| Available Memory | 16 GB |
| Available Memory | 6 GB |
| CPUs | 4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz |
Scenarios
- Angular - node (v14.15.1, x64)
- Compiler-Unions - node (v14.15.1, x64)
- Monaco - node (v14.15.1, x64)
- TFS - node (v14.15.1, x64)
- material-ui - node (v14.15.1, x64)
| Benchmark |
Name |
Iterations |
| Current |
46266 |
10 |
| Baseline |
main |
10 |
Developer Information:Download Benchmark
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
omril1, andrecasal, and GulgDev reacted with rocket emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Martin Probst (mprobst)
pushed a commit
to mprobst/TypeScript
that referenced
this pull request
Jan 10, 2022
…t#46266)
* CFA for dependent variables destructured from discriminated union
* Accept new baselines
* Add tests
* Limit calls to isSymbolAssigned
* Fix wrong operator
|
Daniel Rosenwasser (@DanielRosenwasser) maybe it's worth adding this feature to the 4.6 beta blog post:
https://devblogs.microsoft.com/typescript/announcing-typescript-4-6-beta/#control-flow-analysis-for-dependent-parameters
The blog post does not mention object restructuring, only tuple/union destructuring, but I checked the 4.6 nightly playground and it works with objects too now, which is highly anticipated by React users (more than the example showcased in the blog post IMHO)
Edit: oups actually I'm wrong it's not yet 100% good enough for React, and the following still fails:
import React from "react";
type ItemData =
| { kind: 'user', name: string }
| { kind: 'company', id: string }
function Item({ kind, ...data }: ItemData) {
if (kind === 'user') {
<div>{data.id}</div>
}
if (kind === 'company') {
<div>{data.name}</div>
}
return null;
}
But the following now works:
type ItemData2 =
| { kind: 'user', data: {name: string} }
| { kind: 'company', data: {id: string} }
function Item2({ kind, data }: ItemData2) {
if (kind === 'user') {
<div>{data.name}</div>
}
if (kind === 'company') {
<div>{data.id}</div>
}
return null;
}
Still worth highlighting that in the post :)
|
JuanM04, DanielRosenwasser, sctgraham, luxalpa, and selrond reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Seems like the difference there is the spread, right?
Okay, that's a good call, we must have missed that. I will likely add that to the RC post.
|
slorber, sctgraham, JuanM04, levenleven, nielsdB97, and luxalpa reacted with thumbs up emoji
tonivj5, lafiosca, and cyrilbo reacted with heart emoji
All reactions
-
👍
6 reactions
-
❤️
3 reactions
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Awesome! Thank you so much❤️
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Feb 16, 2022
|
Just a question of understanding: Is the support for the spread syntax planned for a bugfix release or for a minor version? Or is it currently not being planned to be changed / given priority?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Aug 6, 2022
|
I've noticed that this feature doesn't seem to play nice with default values:
type T = {
flag: true;
a: number;
} | {
flag: false;
a: string;
}
// This code works if you remove the "= true"
({ flag = true, a }: T) => {
if (flag) {
a.toFixed(); // thinks it can be either a string or number again
} else {
a.toUpperCase(); // same as above
}
}
Is this also covered by #46680 or is there another reason it doesn't work?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
It's a design limitation, but one we could consider removing. We only do CFA for dependent destructured parameters when they're declared without initializers because it adds complexity to consider the contribution the initializer might make to the inferred declared type of the parameter.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Anders Hejlsberg (@ahejlsberg) intuitively it feels like it should work. In my case (react), the way props work means you have to pass parameters as an object, though I realized that there's other ways to set the default value.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This also does not work when destructuring a nested discriminated union type. See playground link here.
I assume this is because of this line in the PR description:
and the parent type for the destructuring is a discriminated union type
Since the object is nested, the parent type being destructured is not the discriminated union. Still, it's a shame this does not work.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
I am currently running into issues with this (or a related) analysis. I have a union [A, B] | [C, D] | [E, F] and functions isA() isC() isE() and regardless of destructuring or not, narrowing the first tuple member cannot narrow the second tuple member.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
That's a great feature, I personally use it to make global variables dependant on each other:
interface BrowserAPI {
context: "browser";
doBrowserThing(): void;
doNodeThing: never;
}
interface NodeAPI {
context: "node";
doNodeThing(): void;
doBrowserThing: never;
}
declare const api: BrowserAPI | NodeAPI;
const { context, doNodeThing, doBrowserThing } = api;
if (context === "browser") {
doBrowserThing();
} else {
doNodeThing();
}
But it lacks one thing necessary for my usecase: a way to use destructuring in a declaration file (.d.ts). I can't actually perform destructuring, because all the API is defined on the global object at run-time.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|