Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't re-alias top-level type aliases with local type aliases #43701

Merged
merged 2 commits into from
Apr 17, 2021

Conversation

ahejlsberg
Copy link
Member

Fixes #43622.

@ahejlsberg
Copy link
Member Author

I did not add the repro from #43622 as a test since it requires React and other libraries. I have manually verified that #43622 is fixed by this PR, and we already have a test that verifies the new local type alias behavior (see the baseline changes).

Copy link
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

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

This code appears to match the explanation you gave at the design meeting, but I don't understand the feature well enough to predict possible consequences. Is there anything specific you wanted me to test/check?

@@ -50,7 +50,7 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(159,5): error TS2
tests/cases/conformance/types/conditional/conditionalTypes1.ts(160,5): error TS2322: Type 'T' is not assignable to type 'ZeroOf<T>'.
Type 'string | number' is not assignable to type 'ZeroOf<T>'.
Type 'string' is not assignable to type 'ZeroOf<T>'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(263,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'T1', but here has type 'T2'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(263,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'T1', but here has type 'Foo<T & U>'.
Copy link
Member

Choose a reason for hiding this comment

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

This seems worse, but I believe I understood you to say it's just a return to our old behavior?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's a return to the old behavior, the rationale being that Foo<xxx> is accessible outside the function whereas T2 is not. I think very little code will be affected by this change, as it is relatively rare to have local type aliases.

@ahejlsberg
Copy link
Member Author

Is there anything specific you wanted me to test/check?

Not really. I suppose the debatable part is whether we just want to point users at the workaround (i.e. changing xxx to [xxx][0]) and not actually merge this PR.

@amcasey
Copy link
Member

amcasey commented Apr 16, 2021

Is there anything specific you wanted me to test/check?

Not really. I suppose the debatable part is whether we just want to point users at the workaround (i.e. changing xxx to [xxx][0]) and not actually merge this PR.

Is there some way we could supplement tracing to make it clear when a bad expansion happens so that we can at least point users to the relevant type declarations? If we can't assist users in finding where to apply that workaround, I'd be pretty reluctant to recommend they do so.

@DanielRosenwasser
Copy link
Member

@typescript-bot perf test this faster

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 16, 2021

Heya @DanielRosenwasser, I've started to run the perf test suite on this PR at e8f86b3. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 16, 2021

Heya @DanielRosenwasser, I've started to run the abridged perf test suite on this PR at e8f86b3. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - master..43701

Metric master 43701 Delta Best Worst
Angular - node (v14.15.1, x64)
Memory used 321,570k (± 0.01%) 321,561k (± 0.01%) -9k (- 0.00%) 321,489k 321,625k
Parse Time 1.93s (± 0.36%) 1.94s (± 0.73%) +0.01s (+ 0.62%) 1.90s 1.96s
Bind Time 0.87s (± 1.03%) 0.86s (± 0.57%) -0.00s (- 0.23%) 0.86s 0.88s
Check Time 5.13s (± 0.50%) 5.14s (± 0.49%) +0.01s (+ 0.25%) 5.09s 5.19s
Emit Time 6.35s (± 0.82%) 6.35s (± 0.50%) -0.01s (- 0.11%) 6.29s 6.43s
Total Time 14.28s (± 0.47%) 14.29s (± 0.37%) +0.02s (+ 0.11%) 14.21s 14.45s
Compiler-Unions - node (v14.15.1, x64)
Memory used 189,614k (± 0.01%) 189,643k (± 0.02%) +29k (+ 0.02%) 189,543k 189,707k
Parse Time 0.80s (± 0.77%) 0.80s (± 0.59%) -0.00s (- 0.12%) 0.79s 0.81s
Bind Time 0.55s (± 0.66%) 0.56s (± 0.89%) +0.00s (+ 0.36%) 0.55s 0.57s
Check Time 7.10s (± 0.57%) 7.13s (± 0.55%) +0.03s (+ 0.42%) 7.04s 7.22s
Emit Time 2.54s (± 0.88%) 2.56s (± 1.48%) +0.02s (+ 0.83%) 2.51s 2.67s
Total Time 11.00s (± 0.50%) 11.05s (± 0.43%) +0.06s (+ 0.51%) 10.93s 11.17s
Monaco - node (v14.15.1, x64)
Memory used 324,175k (± 0.01%) 324,164k (± 0.01%) -11k (- 0.00%) 324,099k 324,227k
Parse Time 1.57s (± 0.61%) 1.56s (± 0.55%) -0.01s (- 0.83%) 1.54s 1.58s
Bind Time 0.75s (± 0.64%) 0.75s (± 0.89%) 0.00s ( 0.00%) 0.74s 0.76s
Check Time 5.13s (± 0.35%) 5.11s (± 0.40%) -0.02s (- 0.45%) 5.06s 5.15s
Emit Time 3.19s (± 0.60%) 3.19s (± 1.25%) -0.00s (- 0.06%) 3.13s 3.32s
Total Time 10.65s (± 0.22%) 10.61s (± 0.53%) -0.03s (- 0.31%) 10.51s 10.74s
TFS - node (v14.15.1, x64)
Memory used 287,789k (± 0.01%) 287,793k (± 0.01%) +4k (+ 0.00%) 287,737k 287,835k
Parse Time 1.28s (± 1.93%) 1.27s (± 1.19%) -0.01s (- 1.01%) 1.24s 1.30s
Bind Time 0.71s (± 0.42%) 0.72s (± 0.81%) +0.01s (+ 0.70%) 0.71s 0.73s
Check Time 4.72s (± 0.51%) 4.72s (± 0.54%) +0.00s (+ 0.04%) 4.65s 4.76s
Emit Time 3.27s (± 0.90%) 3.26s (± 0.80%) -0.02s (- 0.52%) 3.21s 3.32s
Total Time 9.99s (± 0.49%) 9.96s (± 0.40%) -0.02s (- 0.24%) 9.91s 10.06s
material-ui - node (v14.15.1, x64)
Memory used 441,635k (± 0.01%) 441,647k (± 0.01%) +12k (+ 0.00%) 441,587k 441,686k
Parse Time 2.09s (± 0.53%) 2.10s (± 0.48%) +0.01s (+ 0.33%) 2.08s 2.13s
Bind Time 0.70s (± 0.68%) 0.70s (± 0.49%) +0.00s (+ 0.00%) 0.69s 0.70s
Check Time 13.24s (± 0.66%) 13.18s (± 0.44%) -0.05s (- 0.39%) 13.06s 13.32s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.02s (± 0.58%) 15.98s (± 0.38%) -0.05s (- 0.28%) 15.84s 16.12s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-206-generic
Architecturex64
Available Memory16 GB
Available Memory8 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v14.15.1, x64)
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 43701 10
Baseline master 10

Developer Information:

Download Benchmark

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - master..43701

Metric master 43701 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 345,221k (± 0.03%) 345,199k (± 0.01%) -22k (- 0.01%) 345,127k 345,292k
Parse Time 1.94s (± 0.32%) 1.93s (± 0.40%) -0.01s (- 0.62%) 1.91s 1.94s
Bind Time 0.84s (± 0.98%) 0.84s (± 0.57%) 0.00s ( 0.00%) 0.83s 0.85s
Check Time 5.21s (± 0.50%) 5.20s (± 0.78%) -0.01s (- 0.19%) 5.13s 5.29s
Emit Time 5.93s (± 0.50%) 5.91s (± 0.55%) -0.02s (- 0.37%) 5.86s 5.99s
Total Time 13.92s (± 0.39%) 13.88s (± 0.55%) -0.04s (- 0.32%) 13.76s 14.05s
Compiler-Unions - node (v10.16.3, x64)
Memory used 203,539k (± 0.02%) 203,472k (± 0.03%) -66k (- 0.03%) 203,306k 203,592k
Parse Time 0.78s (± 0.46%) 0.78s (± 0.79%) -0.00s (- 0.38%) 0.77s 0.80s
Bind Time 0.52s (± 1.06%) 0.53s (± 0.69%) +0.00s (+ 0.77%) 0.52s 0.53s
Check Time 7.53s (± 0.65%) 7.56s (± 0.66%) +0.03s (+ 0.39%) 7.46s 7.68s
Emit Time 2.57s (± 0.88%) 2.61s (± 1.55%) +0.03s (+ 1.28%) 2.55s 2.76s
Total Time 11.41s (± 0.46%) 11.47s (± 0.45%) +0.06s (+ 0.56%) 11.35s 11.60s
Monaco - node (v10.16.3, x64)
Memory used 342,751k (± 0.02%) 342,864k (± 0.04%) +112k (+ 0.03%) 342,669k 343,327k
Parse Time 1.56s (± 0.87%) 1.56s (± 0.96%) +0.00s (+ 0.06%) 1.52s 1.59s
Bind Time 0.74s (± 0.70%) 0.74s (± 0.54%) +0.00s (+ 0.27%) 0.73s 0.75s
Check Time 5.33s (± 0.44%) 5.33s (± 0.56%) +0.00s (+ 0.04%) 5.25s 5.39s
Emit Time 3.13s (± 0.88%) 3.13s (± 0.72%) -0.00s (- 0.03%) 3.08s 3.19s
Total Time 10.75s (± 0.42%) 10.76s (± 0.48%) +0.01s (+ 0.07%) 10.62s 10.87s
TFS - node (v10.16.3, x64)
Memory used 304,383k (± 0.02%) 304,339k (± 0.01%) -44k (- 0.01%) 304,229k 304,441k
Parse Time 1.21s (± 0.67%) 1.21s (± 0.68%) +0.00s (+ 0.16%) 1.20s 1.24s
Bind Time 0.70s (± 0.67%) 0.71s (± 0.84%) +0.01s (+ 0.86%) 0.69s 0.72s
Check Time 4.76s (± 0.51%) 4.77s (± 0.43%) +0.01s (+ 0.29%) 4.72s 4.82s
Emit Time 3.26s (± 2.10%) 3.24s (± 1.02%) -0.02s (- 0.46%) 3.18s 3.32s
Total Time 9.93s (± 0.76%) 9.93s (± 0.36%) +0.01s (+ 0.07%) 9.86s 10.00s
material-ui - node (v10.16.3, x64)
Memory used 465,288k (± 0.02%) 465,313k (± 0.01%) +25k (+ 0.01%) 465,155k 465,420k
Parse Time 2.01s (± 0.38%) 2.00s (± 0.46%) -0.01s (- 0.40%) 1.98s 2.02s
Bind Time 0.66s (± 0.79%) 0.66s (± 1.04%) -0.00s (- 0.46%) 0.64s 0.67s
Check Time 14.46s (± 0.72%) 14.38s (± 0.48%) -0.08s (- 0.53%) 14.25s 14.57s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 17.12s (± 0.61%) 17.04s (± 0.39%) -0.09s (- 0.52%) 16.91s 17.21s
Angular - node (v12.1.0, x64)
Memory used 322,965k (± 0.03%) 322,974k (± 0.03%) +9k (+ 0.00%) 322,711k 323,150k
Parse Time 1.93s (± 0.52%) 1.93s (± 0.74%) +0.00s (+ 0.21%) 1.90s 1.96s
Bind Time 0.81s (± 0.58%) 0.81s (± 0.45%) +0.00s (+ 0.12%) 0.81s 0.82s
Check Time 5.11s (± 0.29%) 5.13s (± 0.43%) +0.02s (+ 0.31%) 5.10s 5.19s
Emit Time 5.98s (± 0.41%) 5.96s (± 0.63%) -0.02s (- 0.33%) 5.91s 6.09s
Total Time 13.83s (± 0.21%) 13.83s (± 0.43%) -0.00s (- 0.01%) 13.72s 13.98s
Compiler-Unions - node (v12.1.0, x64)
Memory used 190,507k (± 0.10%) 190,492k (± 0.12%) -15k (- 0.01%) 190,022k 191,021k
Parse Time 0.77s (± 0.58%) 0.77s (± 0.80%) +0.00s (+ 0.39%) 0.76s 0.78s
Bind Time 0.52s (± 0.69%) 0.53s (± 0.94%) +0.00s (+ 0.38%) 0.52s 0.54s
Check Time 7.01s (± 0.56%) 7.03s (± 0.70%) +0.02s (+ 0.24%) 6.95s 7.14s
Emit Time 2.56s (± 1.09%) 2.56s (± 0.75%) -0.00s (- 0.20%) 2.50s 2.59s
Total Time 10.86s (± 0.38%) 10.88s (± 0.45%) +0.01s (+ 0.12%) 10.78s 11.01s
Monaco - node (v12.1.0, x64)
Memory used 325,148k (± 0.02%) 325,138k (± 0.02%) -10k (- 0.00%) 325,003k 325,318k
Parse Time 1.54s (± 0.36%) 1.54s (± 0.83%) +0.00s (+ 0.00%) 1.51s 1.57s
Bind Time 0.72s (± 0.66%) 0.72s (± 0.97%) -0.00s (- 0.55%) 0.71s 0.74s
Check Time 5.16s (± 0.28%) 5.17s (± 0.46%) +0.01s (+ 0.23%) 5.13s 5.22s
Emit Time 3.10s (± 0.70%) 3.11s (± 0.41%) +0.01s (+ 0.19%) 3.07s 3.13s
Total Time 10.52s (± 0.31%) 10.54s (± 0.28%) +0.02s (+ 0.18%) 10.47s 10.60s
TFS - node (v12.1.0, x64)
Memory used 288,841k (± 0.02%) 288,799k (± 0.02%) -42k (- 0.01%) 288,715k 288,957k
Parse Time 1.22s (± 0.90%) 1.21s (± 0.82%) -0.00s (- 0.41%) 1.20s 1.24s
Bind Time 0.69s (± 0.89%) 0.69s (± 0.84%) +0.00s (+ 0.29%) 0.68s 0.71s
Check Time 4.70s (± 0.21%) 4.69s (± 0.74%) -0.01s (- 0.21%) 4.63s 4.78s
Emit Time 3.15s (± 0.68%) 3.16s (± 0.89%) +0.01s (+ 0.22%) 3.08s 3.21s
Total Time 9.76s (± 0.30%) 9.76s (± 0.51%) +0.00s (+ 0.03%) 9.62s 9.85s
material-ui - node (v12.1.0, x64)
Memory used 443,141k (± 0.09%) 443,389k (± 0.06%) +248k (+ 0.06%) 442,382k 443,654k
Parse Time 2.03s (± 0.37%) 2.03s (± 0.46%) +0.01s (+ 0.25%) 2.01s 2.05s
Bind Time 0.64s (± 1.16%) 0.64s (± 0.77%) -0.00s (- 0.63%) 0.63s 0.65s
Check Time 13.13s (± 0.89%) 13.08s (± 0.66%) -0.05s (- 0.40%) 12.96s 13.29s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.79s (± 0.72%) 15.74s (± 0.58%) -0.05s (- 0.30%) 15.63s 15.97s
Angular - node (v14.15.1, x64)
Memory used 321,570k (± 0.01%) 321,605k (± 0.01%) +35k (+ 0.01%) 321,543k 321,663k
Parse Time 1.93s (± 0.36%) 1.93s (± 0.63%) -0.00s (- 0.00%) 1.91s 1.96s
Bind Time 0.87s (± 1.03%) 0.86s (± 0.43%) -0.00s (- 0.12%) 0.86s 0.87s
Check Time 5.13s (± 0.50%) 5.11s (± 0.44%) -0.02s (- 0.41%) 5.06s 5.16s
Emit Time 6.35s (± 0.82%) 6.30s (± 0.60%) -0.06s (- 0.87%) 6.23s 6.38s
Total Time 14.28s (± 0.47%) 14.20s (± 0.43%) -0.08s (- 0.53%) 14.07s 14.37s
Compiler-Unions - node (v14.15.1, x64)
Memory used 189,614k (± 0.01%) 189,625k (± 0.01%) +12k (+ 0.01%) 189,584k 189,661k
Parse Time 0.80s (± 0.77%) 0.80s (± 0.56%) +0.00s (+ 0.12%) 0.79s 0.81s
Bind Time 0.55s (± 0.66%) 0.56s (± 0.89%) +0.00s (+ 0.36%) 0.55s 0.57s
Check Time 7.10s (± 0.57%) 7.09s (± 0.54%) -0.01s (- 0.14%) 7.01s 7.18s
Emit Time 2.54s (± 0.88%) 2.56s (± 0.88%) +0.02s (+ 0.67%) 2.51s 2.61s
Total Time 11.00s (± 0.50%) 11.01s (± 0.47%) +0.01s (+ 0.08%) 10.92s 11.14s
Monaco - node (v14.15.1, x64)
Memory used 324,175k (± 0.01%) 324,161k (± 0.01%) -13k (- 0.00%) 324,079k 324,217k
Parse Time 1.57s (± 0.61%) 1.56s (± 0.61%) -0.01s (- 0.70%) 1.55s 1.59s
Bind Time 0.75s (± 0.64%) 0.75s (± 0.74%) +0.00s (+ 0.13%) 0.74s 0.76s
Check Time 5.13s (± 0.35%) 5.14s (± 0.53%) +0.00s (+ 0.04%) 5.10s 5.22s
Emit Time 3.19s (± 0.60%) 3.18s (± 0.83%) -0.01s (- 0.44%) 3.14s 3.26s
Total Time 10.65s (± 0.22%) 10.63s (± 0.41%) -0.02s (- 0.17%) 10.56s 10.74s
TFS - node (v14.15.1, x64)
Memory used 287,789k (± 0.01%) 287,790k (± 0.01%) +1k (+ 0.00%) 287,750k 287,823k
Parse Time 1.28s (± 1.93%) 1.27s (± 1.32%) -0.01s (- 0.78%) 1.23s 1.31s
Bind Time 0.71s (± 0.42%) 0.71s (± 0.52%) +0.00s (+ 0.42%) 0.71s 0.72s
Check Time 4.72s (± 0.51%) 4.71s (± 0.54%) -0.01s (- 0.17%) 4.66s 4.76s
Emit Time 3.27s (± 0.90%) 3.24s (± 0.48%) -0.04s (- 1.13%) 3.21s 3.27s
Total Time 9.99s (± 0.49%) 9.93s (± 0.48%) -0.06s (- 0.55%) 9.84s 10.02s
material-ui - node (v14.15.1, x64)
Memory used 441,635k (± 0.01%) 441,652k (± 0.00%) +16k (+ 0.00%) 441,608k 441,681k
Parse Time 2.09s (± 0.53%) 2.09s (± 0.74%) -0.00s (- 0.10%) 2.04s 2.12s
Bind Time 0.70s (± 0.68%) 0.70s (± 0.96%) +0.00s (+ 0.00%) 0.68s 0.71s
Check Time 13.24s (± 0.66%) 13.16s (± 0.81%) -0.07s (- 0.55%) 13.02s 13.45s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.02s (± 0.58%) 15.95s (± 0.68%) -0.08s (- 0.47%) 15.79s 16.25s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-206-generic
Architecturex64
Available Memory16 GB
Available Memory8 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)
Benchmark Name Iterations
Current 43701 10
Baseline master 10

Developer Information:

Download Benchmark

@ahejlsberg
Copy link
Member Author

Is there some way we could supplement tracing to make it clear when a bad expansion happens so that we can at least point users to the relevant type declarations?

I can't think of any. If we preserved all possible type aliases then perhaps, but in that case we'd probably just add logic to pick the first accessible alias. But as we discussed in the design meeting, I don't think the additional complexity is merited.

Overall, I think we're better off with the behavior in this PR so I'll merge it.

@ahejlsberg ahejlsberg merged commit 0f2dabc into master Apr 17, 2021
@ahejlsberg ahejlsberg deleted the fix43622 branch April 17, 2021 14:07
sandersn added a commit to DefinitelyTyped/DefinitelyTyped that referenced this pull request Apr 19, 2021
TS 4.3 avoids re-aliasing type aliases needlessly, in
microsoft/TypeScript#43701. This changes the
way that a couple of tests in redux-orm print their type aliases.
sandersn added a commit to DefinitelyTyped/DefinitelyTyped that referenced this pull request Apr 19, 2021
TS 4.3 avoids re-aliasing type aliases needlessly, in
microsoft/TypeScript#43701. This changes the
way that a couple of tests in redux-orm print their type aliases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

React HOCs generate extremely large and incorrect .d.ts declaration files, regression from 4.1.3
4 participants