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

Delete the {} and unconstrained type parameter assignability rule #33570

Conversation

weswigham
Copy link
Member

Fixes #32330

@weswigham weswigham added the Breaking Change Would introduce errors in existing code label Sep 24, 2019
@weswigham
Copy link
Member Author

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

If our baselines are any indication, removing this legacy compat rule is preeeeeeety breaky, but, much like the base change of constraint from {} to unknown, seems to call out a bunch of places where unsound stuff was going on.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 24, 2019

Heya @weswigham, I've started to run the parallelized Definitely Typed test suite on this PR at 248cbba. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 24, 2019

Heya @weswigham, I've started to run the parallelized community code test suite on this PR at 248cbba. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 24, 2019

Heya @weswigham, I've started to run the extended test suite on this PR at 248cbba. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

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

@sandersn sandersn added the For Milestone Bug PRs that fix a bug with a specific milestone label Feb 1, 2020
@sandersn
Copy link
Member

sandersn commented Mar 4, 2020

@weswigham I think the next step is to post an analysis of the breaks. Are there a lot? Are they worth it?

@weswigham
Copy link
Member Author

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 4, 2020

Heya @weswigham, I've started to run the parallelized community code test suite on this PR at 0265829. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 4, 2020

Heya @weswigham, I've started to run the parallelized Definitely Typed test suite on this PR at 0265829. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 4, 2020

Heya @weswigham, I've started to run the extended test suite on this PR at 0265829. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 4, 2020

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - master..33570

Metric master 33570 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 334,376k (± 0.05%) 333,840k (± 0.03%) -536k (- 0.16%) 333,513k 334,060k
Parse Time 1.63s (± 0.72%) 1.61s (± 0.40%) -0.02s (- 1.16%) 1.60s 1.62s
Bind Time 0.89s (± 0.79%) 0.90s (± 0.72%) +0.01s (+ 0.79%) 0.89s 0.91s
Check Time 4.72s (± 0.17%) 4.71s (± 0.49%) -0.01s (- 0.11%) 4.68s 4.79s
Emit Time 5.29s (± 0.57%) 5.31s (± 0.64%) +0.02s (+ 0.44%) 5.21s 5.38s
Total Time 12.53s (± 0.29%) 12.53s (± 0.36%) +0.01s (+ 0.05%) 12.44s 12.69s
Monaco - node (v10.16.3, x64)
Memory used 335,253k (± 0.01%) 335,236k (± 0.02%) -17k (- 0.01%) 335,055k 335,329k
Parse Time 1.26s (± 0.70%) 1.25s (± 0.64%) -0.01s (- 0.72%) 1.23s 1.27s
Bind Time 0.77s (± 0.62%) 0.77s (± 0.44%) 0.00s ( 0.00%) 0.77s 0.78s
Check Time 4.71s (± 0.48%) 4.70s (± 0.50%) -0.01s (- 0.15%) 4.66s 4.77s
Emit Time 2.91s (± 0.94%) 2.90s (± 1.10%) -0.01s (- 0.34%) 2.86s 3.02s
Total Time 9.65s (± 0.51%) 9.62s (± 0.38%) -0.03s (- 0.29%) 9.55s 9.70s
TFS - node (v10.16.3, x64)
Memory used 299,432k (± 0.02%) 299,485k (± 0.01%) +53k (+ 0.02%) 299,365k 299,558k
Parse Time 0.94s (± 0.80%) 0.94s (± 0.32%) -0.01s (- 0.64%) 0.93s 0.94s
Bind Time 0.75s (± 0.78%) 0.74s (± 0.46%) -0.00s (- 0.54%) 0.74s 0.75s
Check Time 4.28s (± 0.35%) 4.26s (± 0.41%) -0.02s (- 0.44%) 4.23s 4.30s
Emit Time 3.04s (± 0.70%) 3.05s (± 0.83%) +0.01s (+ 0.26%) 2.97s 3.09s
Total Time 9.01s (± 0.28%) 8.99s (± 0.40%) -0.02s (- 0.23%) 8.89s 9.06s
material-ui - node (v10.16.3, x64)
Memory used 488,942k (± 0.02%) 488,706k (± 0.01%) -236k (- 0.05%) 488,579k 488,856k
Parse Time 1.78s (± 0.41%) 1.77s (± 0.55%) -0.01s (- 0.51%) 1.75s 1.79s
Bind Time 0.68s (± 1.00%) 0.68s (± 0.87%) -0.00s (- 0.00%) 0.67s 0.70s
Check Time 13.66s (± 0.84%) 13.62s (± 1.21%) -0.04s (- 0.29%) 13.38s 14.08s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.12s (± 0.76%) 16.07s (± 1.07%) -0.05s (- 0.29%) 15.82s 16.57s
Angular - node (v12.1.0, x64)
Memory used 310,082k (± 0.06%) 309,587k (± 0.03%) -495k (- 0.16%) 309,408k 309,884k
Parse Time 1.58s (± 0.49%) 1.56s (± 0.57%) -0.02s (- 1.08%) 1.55s 1.59s
Bind Time 0.87s (± 0.54%) 0.87s (± 0.75%) -0.00s (- 0.23%) 0.86s 0.89s
Check Time 4.63s (± 0.42%) 4.60s (± 0.67%) -0.04s (- 0.80%) 4.53s 4.67s
Emit Time 5.47s (± 1.30%) 5.43s (± 0.50%) -0.04s (- 0.77%) 5.34s 5.47s
Total Time 12.56s (± 0.59%) 12.46s (± 0.40%) -0.10s (- 0.80%) 12.33s 12.55s
Monaco - node (v12.1.0, x64)
Memory used 315,159k (± 0.01%) 315,196k (± 0.02%) +38k (+ 0.01%) 315,061k 315,318k
Parse Time 1.21s (± 0.80%) 1.20s (± 0.80%) -0.01s (- 0.83%) 1.19s 1.23s
Bind Time 0.74s (± 0.83%) 0.74s (± 0.87%) +0.00s (+ 0.41%) 0.73s 0.76s
Check Time 4.56s (± 0.40%) 4.54s (± 0.35%) -0.02s (- 0.44%) 4.51s 4.57s
Emit Time 2.95s (± 0.82%) 2.94s (± 0.41%) -0.01s (- 0.47%) 2.90s 2.96s
Total Time 9.46s (± 0.33%) 9.42s (± 0.27%) -0.04s (- 0.40%) 9.37s 9.47s
TFS - node (v12.1.0, x64)
Memory used 281,710k (± 0.02%) 281,700k (± 0.02%) -10k (- 0.00%) 281,533k 281,845k
Parse Time 0.93s (± 0.75%) 0.92s (± 0.79%) -0.01s (- 0.75%) 0.91s 0.94s
Bind Time 0.70s (± 0.83%) 0.70s (± 0.42%) -0.00s (- 0.14%) 0.70s 0.71s
Check Time 4.17s (± 0.60%) 4.17s (± 0.37%) +0.00s (+ 0.07%) 4.14s 4.21s
Emit Time 3.08s (± 1.12%) 3.09s (± 1.10%) +0.02s (+ 0.59%) 3.04s 3.17s
Total Time 8.88s (± 0.35%) 8.89s (± 0.50%) +0.01s (+ 0.14%) 8.80s 8.98s
material-ui - node (v12.1.0, x64)
Memory used 466,411k (± 0.02%) 466,197k (± 0.01%) -214k (- 0.05%) 466,085k 466,313k
Parse Time 1.75s (± 0.46%) 1.74s (± 0.40%) -0.01s (- 0.63%) 1.72s 1.75s
Bind Time 0.63s (± 1.29%) 0.62s (± 0.64%) -0.01s (- 1.90%) 0.61s 0.63s
Check Time 12.12s (± 0.60%) 12.00s (± 0.33%) -0.12s (- 0.99%) 11.88s 12.07s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 14.50s (± 0.49%) 14.36s (± 0.26%) -0.14s (- 0.98%) 14.26s 14.43s
Angular - node (v8.9.0, x64)
Memory used 329,365k (± 0.01%) 328,930k (± 0.02%) -434k (- 0.13%) 328,797k 329,059k
Parse Time 2.11s (± 0.47%) 2.09s (± 0.39%) -0.02s (- 1.09%) 2.07s 2.10s
Bind Time 0.93s (± 0.74%) 0.92s (± 0.54%) -0.01s (- 1.08%) 0.91s 0.93s
Check Time 5.53s (± 0.58%) 5.45s (± 0.40%) -0.09s (- 1.59%) 5.40s 5.49s
Emit Time 6.24s (± 0.85%) 6.23s (± 0.94%) -0.01s (- 0.19%) 6.07s 6.37s
Total Time 14.81s (± 0.45%) 14.67s (± 0.49%) -0.13s (- 0.90%) 14.56s 14.87s
Monaco - node (v8.9.0, x64)
Memory used 333,571k (± 0.02%) 333,566k (± 0.01%) -5k (- 0.00%) 333,479k 333,646k
Parse Time 1.54s (± 0.46%) 1.54s (± 0.66%) -0.00s (- 0.00%) 1.53s 1.57s
Bind Time 0.90s (± 0.81%) 0.89s (± 1.00%) -0.01s (- 0.89%) 0.88s 0.92s
Check Time 5.41s (± 0.41%) 5.42s (± 0.45%) +0.01s (+ 0.20%) 5.36s 5.47s
Emit Time 3.52s (± 0.38%) 3.51s (± 0.44%) -0.01s (- 0.34%) 3.46s 3.54s
Total Time 11.37s (± 0.28%) 11.36s (± 0.31%) -0.01s (- 0.09%) 11.26s 11.45s
TFS - node (v8.9.0, x64)
Memory used 298,947k (± 0.02%) 298,869k (± 0.01%) -78k (- 0.03%) 298,775k 298,974k
Parse Time 1.25s (± 0.46%) 1.25s (± 0.54%) -0.01s (- 0.48%) 1.24s 1.26s
Bind Time 0.75s (± 0.77%) 0.75s (± 1.12%) +0.00s (+ 0.13%) 0.73s 0.77s
Check Time 4.84s (± 1.45%) 4.80s (± 0.56%) -0.04s (- 0.79%) 4.74s 4.88s
Emit Time 3.35s (± 2.27%) 3.38s (± 0.70%) +0.03s (+ 0.78%) 3.30s 3.43s
Total Time 10.20s (± 0.62%) 10.18s (± 0.31%) -0.02s (- 0.16%) 10.12s 10.26s
material-ui - node (v8.9.0, x64)
Memory used 494,766k (± 0.01%) 494,532k (± 0.01%) -234k (- 0.05%) 494,452k 494,674k
Parse Time 2.10s (± 0.45%) 2.09s (± 0.48%) -0.01s (- 0.29%) 2.08s 2.12s
Bind Time 0.82s (± 1.08%) 0.81s (± 1.00%) -0.01s (- 0.86%) 0.79s 0.83s
Check Time 19.54s (± 0.65%) 19.54s (± 0.91%) -0.00s (- 0.01%) 19.24s 20.03s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 22.46s (± 0.56%) 22.45s (± 0.81%) -0.02s (- 0.07%) 22.15s 22.94s
Angular - node (v8.9.0, x86)
Memory used 188,964k (± 0.03%) 188,718k (± 0.02%) -246k (- 0.13%) 188,638k 188,841k
Parse Time 2.05s (± 0.52%) 2.05s (± 0.87%) +0.00s (+ 0.10%) 2.02s 2.11s
Bind Time 1.07s (± 0.93%) 1.07s (± 0.62%) -0.00s (- 0.28%) 1.06s 1.09s
Check Time 5.03s (± 0.48%) 5.01s (± 0.60%) -0.02s (- 0.32%) 4.95s 5.09s
Emit Time 6.11s (± 0.74%) 6.08s (± 1.00%) -0.03s (- 0.49%) 5.95s 6.21s
Total Time 14.26s (± 0.47%) 14.21s (± 0.48%) -0.05s (- 0.33%) 14.09s 14.38s
Monaco - node (v8.9.0, x86)
Memory used 189,205k (± 0.02%) 189,242k (± 0.02%) +37k (+ 0.02%) 189,157k 189,333k
Parse Time 1.60s (± 1.29%) 1.58s (± 0.42%) -0.02s (- 1.00%) 1.57s 1.60s
Bind Time 0.77s (± 0.84%) 0.76s (± 0.29%) -0.01s (- 1.68%) 0.75s 0.76s
Check Time 5.32s (± 2.05%) 5.32s (± 1.87%) -0.01s (- 0.15%) 5.09s 5.49s
Emit Time 3.03s (± 3.74%) 3.00s (± 3.66%) -0.02s (- 0.73%) 2.83s 3.22s
Total Time 10.72s (± 0.49%) 10.66s (± 0.22%) -0.06s (- 0.57%) 10.60s 10.71s
TFS - node (v8.9.0, x86)
Memory used 170,415k (± 0.02%) 170,408k (± 0.02%) -7k (- 0.00%) 170,329k 170,507k
Parse Time 1.27s (± 0.39%) 1.28s (± 1.01%) +0.00s (+ 0.16%) 1.26s 1.32s
Bind Time 0.71s (± 0.48%) 0.72s (± 0.69%) +0.00s (+ 0.42%) 0.71s 0.73s
Check Time 4.62s (± 0.73%) 4.61s (± 0.56%) -0.00s (- 0.02%) 4.58s 4.69s
Emit Time 2.97s (± 0.77%) 2.98s (± 1.10%) +0.01s (+ 0.34%) 2.88s 3.04s
Total Time 9.58s (± 0.61%) 9.59s (± 0.49%) +0.01s (+ 0.11%) 9.50s 9.71s
material-ui - node (v8.9.0, x86)
Memory used 277,228k (± 0.01%) 277,127k (± 0.02%) -102k (- 0.04%) 277,002k 277,247k
Parse Time 2.17s (± 1.10%) 2.17s (± 0.80%) -0.00s (- 0.23%) 2.14s 2.23s
Bind Time 0.68s (± 1.39%) 0.69s (± 1.95%) +0.00s (+ 0.15%) 0.67s 0.73s
Check Time 17.66s (± 0.99%) 17.65s (± 0.66%) -0.01s (- 0.06%) 17.39s 17.95s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 20.51s (± 0.94%) 20.50s (± 0.60%) -0.01s (- 0.06%) 20.24s 20.82s
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)
Benchmark Name Iterations
Current 33570 10
Baseline master 10

@weswigham
Copy link
Member Author

weswigham commented Mar 4, 2020

Are there a lot?

Yes. Mostly, an unconstrained type parameter is no longer assignable to { [key: string]: any; } or Object or {} (and it shouldn't be - null and undefined aren't...), which is apparently an assumption made in a bunch of types (mongodb, antd, immutable, a small bit of webpack, and some office-ui-fabric in the user suite, plus a bunch in RWC, and knex, mongodb, pouchdb, inquirer, wordpress, slickgrid, mangopay, dialogflow-fulfillment, d3, topojson-client, styled-components (!!!), rrc, mithril, redux-orm, some react components, and jsnox in DT).

Honestly, it looks like a lot in the DT error log, but it's not that bad; there are just some incorrect usages in some very depended-upon packages.

Y'know, it just seems like anywhere where people went "T is our unconstrained schema definition, right? right" not realizing that string and undefined probably aren't valid schema objects. (Or the types predate object)

Are they worth it?

Maybe. Generally speaking, in pretty much every single DT break, the break can be fixed by writing an explicit extends object, as that's normally the original intent.

@weswigham
Copy link
Member Author

Also, ourselves: The sanity check LKG build on pipelines catches us making the same mistake:

src/services/shims.ts(574,73): error TS2345: Argument of type '() => T' is not assignable to parameter of type '() => {}'.
  Type 'T' is not assignable to type '{}'.
src/services/shims.ts(575,62): error TS2352: Conversion of type '{}' to type 'T' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  '{}' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
src/services/utilities.ts(2744,88): error TS2769: No overload matches this call.
  Overload 1 of 2, '(array: readonly {}[], f: (x: {}, i: number) => U): U[]', gave the following error.
    Argument of type '(x: T, i: number) => U' is not assignable to parameter of type '(x: {}, i: number) => U'.
      Types of parameters 'x' and 'x' are incompatible.
        Type '{}' is not assignable to type 'T'.
          '{}' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
  Overload 2 of 2, '(array: readonly {}[] | undefined, f: (x: {}, i: number) => U): U[] | undefined', gave the following error.
    Argument of type '(x: T, i: number) => U' is not assignable to parameter of type '(x: {}, i: number) => U'.
      Types of parameters 'x' and 'x' are incompatible.
        Type '{}' is not assignable to type 'T'.
          '{}' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
src/services/utilities.ts(2744,96): error TS2345: Argument of type 'T | readonly T[]' is not assignable to parameter of type 'T'.
  Type 'readonly T[]' is not assignable to type 'T'.
    'readonly T[]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
src/services/utilities.ts(2751,9): error TS2322: Type '{} | T' is not assignable to type 'T'.
  Type '{}' is not assignable to type 'T'.
    '{}' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.

Namely in shims and core we were using some {} where we should have been using unknown.

@weswigham weswigham added this to the TypeScript 4.0 milestone Mar 6, 2020
@DanielRosenwasser
Copy link
Member

From the design meeting: try to see whether we can at least give an actionable error on this change for users.

@sandersn
Copy link
Member

@weswigham do you want to keep working on this? Seems like it got stuck adding an error.

@weswigham weswigham force-pushed the delete-legacy-empty-obj-type-param-rule branch from 977e511 to bc3d515 Compare October 22, 2020 23:13
@weswigham
Copy link
Member Author

@sandersn This is now synced, and has an informative related span that picks out the type parameter causing the error and suggests giving it an extends object constraint.

@weswigham
Copy link
Member Author

@sandersn do you want to re-milestone this/add it to a design meeting backlog again?

@sandersn
Copy link
Member

Let's bring it up at the design meeting.

@sandersn
Copy link
Member

Did we ever bring this up at a design meeting? We miiight be able to squeeze it in before variance tomorrow or more likely next week.

@weswigham
Copy link
Member Author

Based on my comments saying I implemented design meeting feedback (a helpful related span), we probably did at least once, but not again after that, given there's no linked notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team Breaking Change Would introduce errors in existing code For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Generic bounds not enforced on generic argument
4 participants