Skip to content

Infer instance type arguments as constraint #49863

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

Closed

Conversation

molisani
Copy link
Contributor

@molisani molisani commented Jul 11, 2022

In JavaScript, there are several runtime checks that can determine if an object is an instance of a specific class. However, due to the fact that TypeScript type parameters only exist at the type level, there are limited options for how to handle these when building the class instance reference type. At the moment, there are two different approaches used by the two different kind of checks: one defaults to any and the other re-uses the type argument from the enclosing class. The first could be stricter and the second is possibly too strict in some cases.

The proposed change is to modify the way TypeScript handles these checks such that the type arguments are inferred as the constraint from the corresponding type parameter. This would default to unknown if no constraint was specified as that is the "default constraint".

Fixes #17473 - Infer constrained generic parameters after instanceof check

For instanceof checks, TypeScript mirrors the underlying behavior of JavaScript and looks at the Class.prototype property. This property is computed dynamically in the checker and is then used to narrow the target of the instanceof expression. If the class in question has any type parameters, TypeScript returns a type reference where all of the type arguments are any. This is documented as being part of the "TypeScript 1.0 spec" so it is very long-standing behavior. The proposed change in behavior would constitute a breaking change as it would narrow some types from any to the constraint type or unknown.

class Box<T> { value: T }
Box.prototype; // changes from `Box<any>` to `Box<unknown>`
declare const box: any;
if (box instanceof Box) {
    box; // changes from `Box<any>` to `Box<unknown>`
}

class StringBox<T extends string> { value: T }
StringBox.prototype; // changes from `StringBox<any>` to `StringBox<string>`
declare const stringBox: any;
if (stringBox instanceof StringBox) {
    stringBox; // changes from `StringBox<any>` to `StringBox<string>`
}

Fixes #46668 - Private field check narrows generic class too far

For #brand in obj checks, TypeScript can infer that if an object has a private identifier then it must be an instance of the enclosing class. If the class in question has any type parameters, TypeScript sets all of the type arguments of the inferred type to match the type arguments of this (see thread for potential issues). This behavior was only introduced recently via ergonomic brand checks for private fields. The proposed change in behavior is technically a breaking change, but less so than the instanceof check as in some cases it would loosen type arguments to match their constraint.

class PrivateBox<T> {
    #brand;
    value: T;
    copyValueFrom(other: object) {
        if (#brand in other) {
            other; // changes from `PrivateBox<T>` to `PrivateBox<unknown>`
        }
    }
}

class PrivateStringBox<T extends string> {
    #brand;
    value: T;
    copyValueFrom(other: object) {
        if (#brand in other) {
            other; // changes from `PrivateStringBox<T>` to `PrivateStringBox<string>`
        }
    }
}

Breaking Changes

In order to deal with these breaking changes, this change should be gated behind a new strict compiler option inferInstanceTypeArgumentsAsConstraint. This would be similar to the useUnknownInCatchVariables option that narrowed catch variables from any to unknown (#41013).

For individual instances of this issue, it should be possible to re-widen the narrowed type with a cast:

if (obj instanceof Box) {
    someCodeThatWorksWithAny(obj.value); // now fails with Box<unknown>
    someCodeThatWorksWithAny((obj as Box<any>).value);
}

Addendum on Name: I am aware that this new compiler option name is very verbose, and could potentially be improved. I considered something that referenced "runtime instance checks" but it's hard to include that verbiage in the name and not make it potentially confusing. (ex: Would someone see strictRuntimeInstanceChecks and then assume that it somehow changes runtime behavior?) Also considered useConstraintAsDefaultInstanceTypeArgument or strictDefaultInstanceTypeArguments.

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Jul 11, 2022
@typescript-bot
Copy link
Collaborator

The TypeScript team hasn't accepted the linked issue #17473. If you can get it accepted, this PR will have a better chance of being reviewed.

@molisani molisani force-pushed the infer-instance-type-arg-as-constraint branch from 957043a to 0af9933 Compare July 11, 2022 18:58
@DanielRosenwasser
Copy link
Member

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 11, 2022

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 11, 2022

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 11, 2022

Heya @DanielRosenwasser, I've started to run the tarball bundle task on this PR at 0af9933. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 11, 2022

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 11, 2022

Heya @DanielRosenwasser, I've started to run the diff-based user code test suite on this PR at 0af9933. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

Heya @DanielRosenwasser, I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here.

@typescript-bot
Copy link
Collaborator

@DanielRosenwasser
Great news! no new errors were found between main..refs/pull/49863/merge

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 11, 2022

Hey @DanielRosenwasser, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/129578/artifacts?artifactName=tgz&fileId=F4D99EB49FAC6A21DF04B18E1F2EBD6F62393FDE3B955A27E6A0F3161DA366A502&fileName=/typescript-4.8.0-insiders.20220711.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/[email protected]".;

@typescript-bot
Copy link
Collaborator

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

Here they are:

Compiler

Comparison Report - main..49863
Metric main 49863 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 359,621k (± 0.02%) 359,631k (± 0.02%) +10k (+ 0.00%) 359,494k 359,880k
Parse Time 2.08s (± 0.32%) 2.10s (± 0.65%) +0.01s (+ 0.67%) 2.05s 2.11s
Bind Time 0.89s (± 0.69%) 0.89s (± 0.93%) +0.00s (+ 0.34%) 0.88s 0.91s
Check Time 6.00s (± 0.43%) 6.00s (± 0.53%) -0.00s (- 0.03%) 5.91s 6.05s
Emit Time 6.08s (± 0.83%) 6.11s (± 0.53%) +0.03s (+ 0.46%) 6.02s 6.15s
Total Time 15.05s (± 0.49%) 15.09s (± 0.40%) +0.04s (+ 0.28%) 14.96s 15.20s
Compiler-Unions - node (v10.16.3, x64)
Memory used 206,610k (± 0.03%) 206,634k (± 0.03%) +24k (+ 0.01%) 206,517k 206,796k
Parse Time 0.83s (± 0.91%) 0.83s (± 1.08%) -0.01s (- 0.96%) 0.81s 0.85s
Bind Time 0.53s (± 1.81%) 0.53s (± 1.69%) +0.00s (+ 0.00%) 0.51s 0.54s
Check Time 7.09s (± 0.31%) 7.08s (± 0.49%) -0.01s (- 0.10%) 7.02s 7.18s
Emit Time 2.49s (± 0.79%) 2.49s (± 0.82%) -0.00s (- 0.08%) 2.45s 2.55s
Total Time 10.94s (± 0.20%) 10.92s (± 0.38%) -0.02s (- 0.15%) 10.83s 11.02s
Monaco - node (v10.16.3, x64)
Memory used 343,974k (± 0.02%) 343,992k (± 0.01%) +18k (+ 0.01%) 343,930k 344,138k
Parse Time 1.59s (± 0.72%) 1.60s (± 0.89%) +0.01s (+ 0.50%) 1.56s 1.63s
Bind Time 0.77s (± 0.84%) 0.77s (± 0.84%) 0.00s ( 0.00%) 0.76s 0.78s
Check Time 5.97s (± 0.55%) 5.97s (± 0.49%) +0.00s (+ 0.02%) 5.89s 6.03s
Emit Time 3.26s (± 0.79%) 3.27s (± 0.67%) +0.02s (+ 0.61%) 3.22s 3.33s
Total Time 11.59s (± 0.52%) 11.62s (± 0.42%) +0.03s (+ 0.25%) 11.53s 11.73s
TFS - node (v10.16.3, x64)
Memory used 305,163k (± 0.02%) 305,199k (± 0.03%) +37k (+ 0.01%) 305,059k 305,370k
Parse Time 1.28s (± 0.53%) 1.28s (± 0.82%) -0.00s (- 0.08%) 1.26s 1.31s
Bind Time 0.72s (± 0.72%) 0.72s (± 0.80%) +0.00s (+ 0.56%) 0.71s 0.73s
Check Time 5.41s (± 0.32%) 5.40s (± 0.54%) -0.01s (- 0.13%) 5.33s 5.47s
Emit Time 3.43s (± 1.04%) 3.44s (± 1.16%) +0.01s (+ 0.20%) 3.37s 3.58s
Total Time 10.85s (± 0.34%) 10.85s (± 0.61%) +0.00s (+ 0.00%) 10.67s 10.98s
material-ui - node (v10.16.3, x64)
Memory used 469,473k (± 0.01%) 469,489k (± 0.01%) +16k (+ 0.00%) 469,391k 469,568k
Parse Time 1.83s (± 0.72%) 1.83s (± 0.60%) 0.00s ( 0.00%) 1.81s 1.85s
Bind Time 0.69s (± 1.36%) 0.69s (± 1.29%) +0.00s (+ 0.72%) 0.67s 0.72s
Check Time 14.53s (± 0.67%) 14.54s (± 0.57%) +0.00s (+ 0.01%) 14.37s 14.75s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 17.05s (± 0.57%) 17.06s (± 0.47%) +0.01s (+ 0.05%) 16.90s 17.26s
xstate - node (v10.16.3, x64)
Memory used 584,558k (± 1.66%) 577,945k (± 0.02%) -6,613k (- 1.13%) 577,761k 578,156k
Parse Time 2.60s (± 0.30%) 2.60s (± 0.53%) -0.00s (- 0.15%) 2.57s 2.62s
Bind Time 1.02s (± 0.58%) 1.03s (± 1.13%) +0.00s (+ 0.20%) 1.00s 1.05s
Check Time 1.55s (± 0.30%) 1.55s (± 0.52%) 0.00s ( 0.00%) 1.53s 1.57s
Emit Time 0.07s (± 3.14%) 0.07s (± 3.14%) 0.00s ( 0.00%) 0.07s 0.08s
Total Time 5.24s (± 0.19%) 5.24s (± 0.37%) +0.00s (+ 0.00%) 5.18s 5.27s
Angular - node (v12.1.0, x64)
Memory used 337,264k (± 0.02%) 337,230k (± 0.01%) -33k (- 0.01%) 337,171k 337,334k
Parse Time 2.09s (± 0.90%) 2.09s (± 0.76%) +0.00s (+ 0.05%) 2.08s 2.15s
Bind Time 0.86s (± 0.55%) 0.86s (± 0.75%) -0.01s (- 0.58%) 0.84s 0.87s
Check Time 5.79s (± 0.39%) 5.79s (± 0.49%) +0.01s (+ 0.14%) 5.74s 5.88s
Emit Time 6.38s (± 0.38%) 6.42s (± 0.93%) +0.04s (+ 0.61%) 6.30s 6.56s
Total Time 15.12s (± 0.27%) 15.16s (± 0.52%) +0.04s (+ 0.24%) 15.01s 15.28s
Compiler-Unions - node (v12.1.0, x64)
Memory used 194,158k (± 0.15%) 194,226k (± 0.08%) +68k (+ 0.04%) 193,678k 194,415k
Parse Time 0.83s (± 0.97%) 0.82s (± 0.45%) -0.00s (- 0.36%) 0.82s 0.83s
Bind Time 0.54s (± 0.63%) 0.55s (± 0.73%) +0.01s (+ 1.10%) 0.54s 0.56s
Check Time 6.71s (± 0.46%) 6.71s (± 0.54%) -0.00s (- 0.03%) 6.62s 6.79s
Emit Time 2.56s (± 1.42%) 2.54s (± 1.33%) -0.02s (- 0.66%) 2.47s 2.64s
Total Time 10.64s (± 0.55%) 10.63s (± 0.51%) -0.02s (- 0.17%) 10.50s 10.76s
Monaco - node (v12.1.0, x64)
Memory used 327,026k (± 0.01%) 327,031k (± 0.03%) +5k (+ 0.00%) 326,896k 327,264k
Parse Time 1.57s (± 0.73%) 1.56s (± 0.70%) -0.01s (- 0.64%) 1.55s 1.60s
Bind Time 0.76s (± 0.92%) 0.76s (± 0.76%) -0.00s (- 0.13%) 0.75s 0.77s
Check Time 5.78s (± 0.42%) 5.78s (± 0.36%) +0.00s (+ 0.09%) 5.74s 5.82s
Emit Time 3.29s (± 0.32%) 3.30s (± 0.55%) +0.01s (+ 0.33%) 3.26s 3.35s
Total Time 11.40s (± 0.28%) 11.41s (± 0.29%) +0.01s (+ 0.07%) 11.33s 11.47s
TFS - node (v12.1.0, x64)
Memory used 289,730k (± 0.02%) 289,755k (± 0.06%) +25k (+ 0.01%) 289,105k 289,937k
Parse Time 1.29s (± 0.63%) 1.30s (± 0.77%) +0.01s (+ 0.78%) 1.28s 1.33s
Bind Time 0.73s (± 1.11%) 0.73s (± 0.68%) -0.00s (- 0.55%) 0.72s 0.74s
Check Time 5.35s (± 0.25%) 5.34s (± 0.50%) -0.01s (- 0.09%) 5.28s 5.40s
Emit Time 3.50s (± 0.74%) 3.52s (± 0.88%) +0.03s (+ 0.74%) 3.45s 3.60s
Total Time 10.86s (± 0.35%) 10.89s (± 0.48%) +0.03s (+ 0.24%) 10.75s 10.97s
material-ui - node (v12.1.0, x64)
Memory used 448,534k (± 0.01%) 448,524k (± 0.02%) -9k (- 0.00%) 448,339k 448,716k
Parse Time 1.82s (± 0.25%) 1.83s (± 0.55%) +0.01s (+ 0.50%) 1.80s 1.85s
Bind Time 0.68s (± 0.73%) 0.68s (± 0.76%) +0.00s (+ 0.74%) 0.67s 0.69s
Check Time 13.01s (± 0.27%) 13.01s (± 0.55%) -0.00s (- 0.01%) 12.89s 13.23s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.51s (± 0.21%) 15.52s (± 0.52%) +0.01s (+ 0.08%) 15.38s 15.76s
xstate - node (v12.1.0, x64)
Memory used 543,512k (± 0.01%) 549,870k (± 1.74%) +6,358k (+ 1.17%) 543,272k 575,783k
Parse Time 2.55s (± 0.33%) 2.55s (± 0.55%) +0.00s (+ 0.20%) 2.53s 2.60s
Bind Time 1.03s (± 1.04%) 1.03s (± 0.75%) 0.00s ( 0.00%) 1.01s 1.04s
Check Time 1.49s (± 0.39%) 1.50s (± 0.37%) +0.01s (+ 0.33%) 1.49s 1.51s
Emit Time 0.07s (± 0.00%) 0.07s (± 0.00%) 0.00s ( 0.00%) 0.07s 0.07s
Total Time 5.15s (± 0.15%) 5.16s (± 0.44%) +0.01s (+ 0.25%) 5.12s 5.20s
Angular - node (v14.15.1, x64)
Memory used 335,391k (± 0.01%) 335,417k (± 0.01%) +26k (+ 0.01%) 335,324k 335,464k
Parse Time 2.05s (± 0.60%) 2.06s (± 0.49%) +0.02s (+ 0.83%) 2.05s 2.10s
Bind Time 0.90s (± 0.58%) 0.91s (± 1.32%) +0.01s (+ 0.89%) 0.89s 0.95s
Check Time 5.80s (± 0.44%) 5.79s (± 0.40%) -0.02s (- 0.33%) 5.73s 5.84s
Emit Time 6.35s (± 0.60%) 6.35s (± 0.76%) +0.00s (+ 0.00%) 6.25s 6.48s
Total Time 15.10s (± 0.36%) 15.11s (± 0.40%) +0.01s (+ 0.06%) 14.99s 15.27s
Compiler-Unions - node (v14.15.1, x64)
Memory used 192,860k (± 0.02%) 192,746k (± 0.11%) -114k (- 0.06%) 191,886k 192,915k
Parse Time 0.84s (± 0.59%) 0.85s (± 0.47%) +0.01s (+ 0.71%) 0.84s 0.86s
Bind Time 0.57s (± 0.70%) 0.57s (± 1.19%) +0.01s (+ 0.88%) 0.56s 0.59s
Check Time 6.70s (± 0.42%) 6.71s (± 0.44%) +0.01s (+ 0.13%) 6.64s 6.77s
Emit Time 2.49s (± 0.68%) 2.51s (± 0.93%) +0.02s (+ 0.80%) 2.48s 2.57s
Total Time 10.60s (± 0.36%) 10.64s (± 0.43%) +0.04s (+ 0.36%) 10.55s 10.76s
Monaco - node (v14.15.1, x64)
Memory used 325,726k (± 0.01%) 325,728k (± 0.01%) +2k (+ 0.00%) 325,693k 325,788k
Parse Time 1.59s (± 1.03%) 1.59s (± 0.96%) -0.00s (- 0.00%) 1.56s 1.64s
Bind Time 0.80s (± 0.75%) 0.79s (± 0.70%) -0.00s (- 0.38%) 0.78s 0.80s
Check Time 5.69s (± 0.42%) 5.70s (± 0.42%) +0.00s (+ 0.04%) 5.63s 5.74s
Emit Time 3.36s (± 1.21%) 3.38s (± 0.96%) +0.02s (+ 0.48%) 3.32s 3.45s
Total Time 11.43s (± 0.48%) 11.45s (± 0.47%) +0.02s (+ 0.17%) 11.30s 11.55s
TFS - node (v14.15.1, x64)
Memory used 288,805k (± 0.01%) 288,812k (± 0.01%) +8k (+ 0.00%) 288,765k 288,851k
Parse Time 1.34s (± 1.85%) 1.35s (± 1.82%) +0.02s (+ 1.20%) 1.29s 1.42s
Bind Time 0.76s (± 3.01%) 0.76s (± 3.28%) -0.00s (- 0.26%) 0.73s 0.85s
Check Time 5.32s (± 0.50%) 5.34s (± 0.66%) +0.02s (+ 0.32%) 5.28s 5.46s
Emit Time 3.56s (± 2.16%) 3.61s (± 2.29%) +0.05s (+ 1.41%) 3.43s 3.75s
Total Time 10.98s (± 0.84%) 11.05s (± 0.87%) +0.08s (+ 0.72%) 10.88s 11.30s
material-ui - node (v14.15.1, x64)
Memory used 446,685k (± 0.01%) 446,561k (± 0.06%) -124k (- 0.03%) 445,520k 446,733k
Parse Time 1.87s (± 0.36%) 1.88s (± 0.64%) +0.00s (+ 0.27%) 1.85s 1.90s
Bind Time 0.73s (± 0.71%) 0.73s (± 0.89%) -0.00s (- 0.14%) 0.71s 0.74s
Check Time 13.12s (± 0.65%) 13.26s (± 1.20%) +0.14s (+ 1.09%) 12.96s 13.62s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.72s (± 0.54%) 15.87s (± 1.01%) +0.15s (+ 0.94%) 15.55s 16.21s
xstate - node (v14.15.1, x64)
Memory used 541,284k (± 0.00%) 541,289k (± 0.00%) +5k (+ 0.00%) 541,259k 541,350k
Parse Time 2.60s (± 0.69%) 2.61s (± 0.44%) +0.02s (+ 0.66%) 2.58s 2.63s
Bind Time 1.14s (± 0.91%) 1.14s (± 1.25%) +0.00s (+ 0.26%) 1.11s 1.17s
Check Time 1.54s (± 0.36%) 1.55s (± 0.38%) +0.00s (+ 0.26%) 1.53s 1.56s
Emit Time 0.07s (± 4.95%) 0.07s (± 4.92%) -0.00s (- 1.33%) 0.07s 0.08s
Total Time 5.35s (± 0.36%) 5.37s (± 0.38%) +0.02s (+ 0.32%) 5.33s 5.42s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory15 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)
  • xstate - node (v10.16.3, x64)
  • xstate - node (v12.1.0, x64)
  • xstate - node (v14.15.1, x64)
Benchmark Name Iterations
Current 49863 10
Baseline main 10

TSServer

Comparison Report - main..49863
Metric main 49863 Delta Best Worst
xstateTSServer - node (v10.16.3, x64)
Initial load time 2,153.30ms (± 0.46%) 2,161.60ms (± 0.30%) +8.30ms (+ 0.39%) 2,148.00ms 2,173.00ms
Geterr time 759.60ms (± 0.53%) 761.10ms (± 0.60%) +1.50ms (+ 0.20%) 753.00ms 774.00ms
References time 95.60ms (± 0.71%) 95.80ms (± 1.38%) +0.20ms (+ 0.21%) 93.00ms 98.00ms
Navto time 250.20ms (± 1.12%) 254.10ms (± 0.71%) +3.90ms (+ 1.56%) 249.00ms 258.00ms
Navto count 256.00 (± 0.00%) 256.00 (± 0.00%) 0.00 ( 0.00%) 256.00 256.00
Completions time 244.70ms (± 1.15%) 246.10ms (± 0.76%) +1.40ms (+ 0.57%) 241.00ms 250.00ms
Completions count 3,205.00 (± 0.00%) 3,205.00 (± 0.00%) 0.00 ( 0.00%) 3,205.00 3,205.00
xstateTSServer - node (v12.1.0, x64)
Initial load time 2,092.10ms (± 0.31%) 2,092.40ms (± 0.52%) +0.30ms (+ 0.01%) 2,062.00ms 2,113.00ms
Geterr time 750.60ms (± 0.59%) 747.30ms (± 0.61%) -3.30ms (- 0.44%) 738.00ms 757.00ms
References time 69.30ms (± 1.66%) 68.00ms (± 1.62%) -1.30ms (- 1.88%) 65.00ms 71.00ms
Navto time 240.10ms (± 1.87%) 243.30ms (± 2.12%) +3.20ms (+ 1.33%) 230.00ms 260.00ms
Navto count 256.00 (± 0.00%) 256.00 (± 0.00%) 0.00 ( 0.00%) 256.00 256.00
Completions time 239.00ms (± 0.99%) 240.20ms (± 0.90%) +1.20ms (+ 0.50%) 235.00ms 244.00ms
Completions count 3,205.00 (± 0.00%) 3,205.00 (± 0.00%) 0.00 ( 0.00%) 3,205.00 3,205.00
xstateTSServer - node (v14.15.1, x64)
Initial load time 2,231.40ms (± 0.38%) 2,219.60ms (± 0.45%) -11.80ms (- 0.53%) 2,197.00ms 2,241.00ms
Geterr time 769.30ms (± 0.51%) 769.80ms (± 0.53%) +0.50ms (+ 0.06%) 761.00ms 778.00ms
References time 65.40ms (± 2.11%) 65.20ms (± 1.23%) -0.20ms (- 0.31%) 64.00ms 68.00ms
Navto time 250.20ms (± 0.89%) 250.60ms (± 0.84%) +0.40ms (+ 0.16%) 248.00ms 257.00ms
Navto count 256.00 (± 0.00%) 256.00 (± 0.00%) 0.00 ( 0.00%) 256.00 256.00
Completions time 242.00ms (± 0.34%) 242.50ms (± 0.53%) +0.50ms (+ 0.21%) 239.00ms 245.00ms
Completions count 3,205.00 (± 0.00%) 3,205.00 (± 0.00%) 0.00 ( 0.00%) 3,205.00 3,205.00
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory15 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
  • xstateTSServer - node (v10.16.3, x64)
  • xstateTSServer - node (v12.1.0, x64)
  • xstateTSServer - node (v14.15.1, x64)
Benchmark Name Iterations
Current 49863 10
Baseline main 10

Developer Information:

Download Benchmark

@molisani
Copy link
Contributor Author

Here's a playground link that contains both code samples from the description, for convenience: 4.8.0-pr-49863-9

@sandersn sandersn requested review from ahejlsberg and weswigham July 21, 2022 00:03
@molisani
Copy link
Contributor Author

I've been thinking more about this issue, specifically in the context of type parameter variance when a custom extends is specified. (The following comments do not effect the base case <T> where any switches to unknown)

For <T extends U>, if T was contravariant or invariant, than it would be unsafe to choose U as the type argument. Therefore, it is really only safe to choose U as the type argument if T is covariant. How should we account for this? If we use the variance annotations we can make some decisions:

  • <out T extends U> type argument should default to U
  • <in T extends U> type argument should default to unknown
  • <in out T extends U> type argument should default to unknown

We also then need to decide what happens in the absence of those annotations <T extends U>. The safest option would probably be to widen to unknown, but keeping it as-is (U) may also be a reasonable strategy. It would let more people use this feature immediately and the variance annotations could act as a way to formally opt-in (or opt-out, depending on perspective).

What does everyone think?

@DanielRosenwasser
Copy link
Member

<in T extends U> type argument should default to unknown

This should be never, right? If you have

declare class HasAction<T> {
  readonly fn: (x: T) => void;
}

then you want the most restrictive instantiation of HasAction<T> to instantiate T with its lower-bound.

@molisani
Copy link
Contributor Author

This should be never, right?

Ah, never instead of unknown makes sense. So that would make it:

  • <out T extends U> defaults to U
  • <in T extends U> defaults to never
  • <in out T extends U> defaults to never
  • <T extends U> defaults to never (or maybe U for usability?)

And then for <T> it would be the same for the above except U = unknown.

@molisani
Copy link
Contributor Author

In this latest commit, I've updated the behavior such that the presence of an in variance annotation on the type parameter will force the inferred type argument to be never. This does not effect the default case (no variance annotations) which is unchanged, for now.

  • <T extends U> defaults to U
  • <out T extends U> defaults to U
  • <in T extends U> defaults to never
  • <in out T extends U> defaults to never

@molisani molisani force-pushed the infer-instance-type-arg-as-constraint branch from e58a84d to b74922b Compare October 5, 2022 16:43
@molisani
Copy link
Contributor Author

molisani commented Oct 5, 2022

Rebased, but the license/cla check is incomplete where it wasn't previously.

@molisani molisani force-pushed the infer-instance-type-arg-as-constraint branch from f02417c to e10367e Compare November 2, 2022 14:29
@molisani
Copy link
Contributor Author

molisani commented Nov 2, 2022

@microsoft-github-policy-service agree company="Bloomberg"

@molisani
Copy link
Contributor Author

molisani commented Nov 2, 2022

Seems like the CLA bot is broken 😢

EDIT: Or not? The license/cla check was successful

@molisani molisani force-pushed the infer-instance-type-arg-as-constraint branch from e10367e to 5f51450 Compare November 2, 2022 14:55
@weswigham weswigham added the Breaking Change Would introduce errors in existing code label Nov 7, 2022
Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

Honestly unsure if this should be its own flag - this looks a lot like an implicit any we're removing to me, so I could see it as a justifiable breaking change under the noImplicitAny flag. Depends on how breaky we wanna be, which I guess we'd have to discuss at a design meeting @DanielRosenwasser .

@whzx5byb
Copy link

What about instantiation expressions? I think (StringBox<'foo'>).prototype should be StringBox<'foo'> instead of StringBox<string>.

@DanielRosenwasser
Copy link
Member

@typescript-bot pack this
@typescript-bot test this
@typescript-bot test top100
@typescript-bot user test this
@typescript-bot user test tsserver
@typescript-bot test tsserver top100
@typescript-bot run dt
@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

Heya @DanielRosenwasser, I've started to run the tarball bundle task on this PR at 0106a18. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

Heya @DanielRosenwasser, I've started to run the diff-based user code test suite (tsserver) on this PR at 0106a18. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

Heya @DanielRosenwasser, I've started to run the diff-based top-repos suite on this PR at 0106a18. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

Heya @DanielRosenwasser, I've started to run the diff-based top-repos suite (tsserver) on this PR at 0106a18. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

Heya @DanielRosenwasser, I've started to run the diff-based user code test suite on this PR at 0106a18. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

Hey @DanielRosenwasser, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/150584/artifacts?artifactName=tgz&fileId=05638CD6670B3BF986761992DDFACD2633553681A499791FEFFA85B5BAD71C5702&fileName=/typescript-5.1.0-insiders.20230321.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/[email protected]".;

@typescript-bot
Copy link
Collaborator

@DanielRosenwasser Here are the results of running the user test suite comparing main and refs/pull/49863/merge:

Everything looks good!

1 similar comment
@typescript-bot
Copy link
Collaborator

@DanielRosenwasser Here are the results of running the user test suite comparing main and refs/pull/49863/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

Heya @DanielRosenwasser, I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here.

@typescript-bot
Copy link
Collaborator

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

Here they are:

Compiler

Comparison Report - main..49863
Metric main 49863 Delta Best Worst p-value
Angular - node (v18.10.0, x64)
Memory used 362,083k (± 0.01%) 362,114k (± 0.00%) ~ 362,101k 362,129k p=0.109 n=6
Parse Time 3.38s (± 0.51%) 3.39s (± 0.81%) ~ 3.36s 3.43s p=0.415 n=6
Bind Time 1.12s (± 0.36%) 1.12s (± 0.36%) ~ 1.11s 1.12s p=1.000 n=6
Check Time 8.70s (± 0.25%) 8.73s (± 0.24%) ~ 8.70s 8.76s p=0.062 n=6
Emit Time 7.43s (± 0.60%) 7.44s (± 0.47%) ~ 7.39s 7.47s p=0.685 n=6
Total Time 20.63s (± 0.26%) 20.68s (± 0.16%) ~ 20.64s 20.73s p=0.077 n=6
Compiler-Unions - node (v18.10.0, x64)
Memory used 191,878k (± 1.20%) 191,881k (± 1.18%) ~ 190,937k 196,500k p=0.378 n=6
Parse Time 1.50s (± 0.78%) 1.49s (± 1.07%) ~ 1.46s 1.50s p=1.000 n=6
Bind Time 0.76s (± 0.00%) 0.77s (± 1.06%) ~ 0.76s 0.78s p=0.073 n=6
Check Time 9.42s (± 0.32%) 9.43s (± 0.62%) ~ 9.36s 9.53s p=0.936 n=6
Emit Time 2.73s (± 1.02%) 2.74s (± 0.97%) ~ 2.71s 2.78s p=0.466 n=6
Total Time 14.41s (± 0.31%) 14.43s (± 0.45%) ~ 14.35s 14.52s p=0.519 n=6
Monaco - node (v18.10.0, x64)
Memory used 346,301k (± 0.01%) 346,276k (± 0.01%) ~ 346,243k 346,296k p=0.295 n=6
Parse Time 2.59s (± 0.90%) 2.58s (± 1.10%) ~ 2.55s 2.62s p=0.331 n=6
Bind Time 1.01s (± 1.20%) 1.01s (± 0.97%) ~ 1.00s 1.02s p=0.720 n=6
Check Time 7.06s (± 0.28%) 7.04s (± 0.48%) ~ 6.98s 7.07s p=0.459 n=6
Emit Time 4.23s (± 0.54%) 4.23s (± 0.72%) ~ 4.20s 4.28s p=0.935 n=6
Total Time 14.89s (± 0.26%) 14.86s (± 0.54%) ~ 14.74s 14.99s p=0.103 n=6
TFS - node (v18.10.0, x64)
Memory used 300,458k (± 0.01%) 300,443k (± 0.00%) ~ 300,425k 300,459k p=0.575 n=6
Parse Time 2.06s (± 1.47%) 2.05s (± 1.05%) ~ 2.03s 2.09s p=0.466 n=6
Bind Time 1.14s (± 0.66%) 1.14s (± 0.66%) ~ 1.13s 1.15s p=0.487 n=6
Check Time 6.55s (± 0.78%) 6.50s (± 0.39%) ~ 6.47s 6.54s p=0.064 n=6
Emit Time 3.84s (± 0.48%) 3.84s (± 0.51%) ~ 3.80s 3.85s p=0.803 n=6
Total Time 13.58s (± 0.53%) 13.53s (± 0.29%) ~ 13.48s 13.59s p=0.148 n=6
material-ui - node (v18.10.0, x64)
Memory used 477,186k (± 0.01%) 477,145k (± 0.01%) ~ 477,110k 477,188k p=0.298 n=6
Parse Time 3.03s (± 1.81%) 3.06s (± 0.94%) ~ 3.03s 3.11s p=0.226 n=6
Bind Time 0.93s (± 6.86%) 0.91s (± 1.32%) ~ 0.90s 0.93s p=0.557 n=6
Check Time 17.09s (± 0.43%) 17.14s (± 0.43%) ~ 17.06s 17.27s p=0.466 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 21.05s (± 0.37%) 21.11s (± 0.34%) ~ 21.05s 21.25s p=0.377 n=6
xstate - node (v18.10.0, x64)
Memory used 552,873k (± 0.01%) 552,913k (± 0.01%) ~ 552,841k 553,055k p=0.336 n=6
Parse Time 3.77s (± 0.41%) 3.78s (± 0.73%) ~ 3.74s 3.81s p=0.508 n=6
Bind Time 1.70s (± 0.80%) 1.69s (± 0.71%) ~ 1.68s 1.71s p=0.804 n=6
Check Time 2.80s (± 1.11%) 2.80s (± 1.07%) ~ 2.76s 2.85s p=0.683 n=6
Emit Time 0.08s (± 0.00%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=1.000 n=6
Total Time 8.36s (± 0.45%) 8.36s (± 0.49%) ~ 8.32s 8.44s p=0.809 n=6
Angular - node (v16.17.1, x64)
Memory used 361,422k (± 0.01%) 361,450k (± 0.01%) ~ 361,419k 361,523k p=0.078 n=6
Parse Time 3.53s (± 0.85%) 3.52s (± 0.92%) ~ 3.49s 3.58s p=0.292 n=6
Bind Time 1.18s (± 0.88%) 1.19s (± 0.43%) ~ 1.18s 1.19s p=0.070 n=6
Check Time 9.53s (± 0.16%) 9.52s (± 0.49%) ~ 9.48s 9.60s p=0.746 n=6
Emit Time 7.94s (± 0.49%) 7.93s (± 0.45%) ~ 7.88s 7.98s p=0.688 n=6
Total Time 22.18s (± 0.21%) 22.16s (± 0.31%) ~ 22.07s 22.26s p=0.574 n=6
Compiler-Unions - node (v16.17.1, x64)
Memory used 192,532k (± 0.03%) 193,132k (± 0.70%) ~ 192,538k 195,878k p=0.128 n=6
Parse Time 1.59s (± 0.65%) 1.58s (± 1.62%) ~ 1.55s 1.61s p=0.511 n=6
Bind Time 0.82s (± 0.77%) 0.82s (± 0.63%) ~ 0.81s 0.82s p=0.386 n=6
Check Time 10.13s (± 0.29%) 10.10s (± 0.12%) ~ 10.09s 10.12s p=0.063 n=6
Emit Time 2.99s (± 1.21%) 2.98s (± 1.01%) ~ 2.93s 3.01s p=0.330 n=6
Total Time 15.54s (± 0.31%) 15.47s (± 0.34%) ~ 15.42s 15.54s p=0.091 n=6
Monaco - node (v16.17.1, x64)
Memory used 345,570k (± 0.01%) 345,558k (± 0.01%) ~ 345,523k 345,582k p=0.471 n=6
Parse Time 2.73s (± 0.31%) 2.72s (± 0.28%) ~ 2.71s 2.73s p=0.172 n=6
Bind Time 1.09s (± 0.69%) 1.09s (± 0.96%) ~ 1.08s 1.11s p=0.273 n=6
Check Time 7.74s (± 0.18%) 7.75s (± 0.48%) ~ 7.71s 7.80s p=0.520 n=6
Emit Time 4.46s (± 0.46%) 4.48s (± 1.08%) ~ 4.42s 4.54s p=0.520 n=6
Total Time 16.02s (± 0.12%) 16.05s (± 0.53%) ~ 15.93s 16.15s p=0.688 n=6
TFS - node (v16.17.1, x64)
Memory used 299,816k (± 0.01%) 299,823k (± 0.02%) ~ 299,749k 299,871k p=0.630 n=6
Parse Time 2.18s (± 0.54%) 2.17s (± 0.48%) ~ 2.15s 2.18s p=0.117 n=6
Bind Time 1.24s (± 0.83%) 1.24s (± 1.56%) ~ 1.21s 1.26s p=0.933 n=6
Check Time 7.21s (± 0.62%) 7.19s (± 0.48%) ~ 7.15s 7.25s p=0.414 n=6
Emit Time 4.33s (± 0.27%) 4.34s (± 0.38%) ~ 4.31s 4.36s p=0.288 n=6
Total Time 14.96s (± 0.37%) 14.94s (± 0.45%) ~ 14.83s 15.04s p=0.520 n=6
material-ui - node (v16.17.1, x64)
Memory used 476,413k (± 0.00%) 476,421k (± 0.00%) ~ 476,399k 476,446k p=0.471 n=6
Parse Time 3.22s (± 0.36%) 3.22s (± 0.43%) ~ 3.19s 3.23s p=1.000 n=6
Bind Time 0.95s (± 0.57%) 0.96s (± 0.54%) ~ 0.95s 0.96s p=0.640 n=6
Check Time 18.10s (± 0.29%) 18.18s (± 0.24%) ~ 18.15s 18.26s p=0.050 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 22.28s (± 0.22%) 22.35s (± 0.22%) ~ 22.30s 22.43s p=0.053 n=6
xstate - node (v16.17.1, x64)
Memory used 550,480k (± 0.02%) 550,575k (± 0.03%) ~ 550,451k 550,850k p=0.298 n=6
Parse Time 3.94s (± 0.14%) 3.94s (± 0.16%) +0.00s (+ 0.13%) 3.93s 3.95s p=0.030 n=6
Bind Time 1.79s (± 0.92%) 1.80s (± 0.77%) ~ 1.77s 1.81s p=0.254 n=6
Check Time 3.03s (± 1.34%) 3.05s (± 0.81%) ~ 3.02s 3.09s p=0.195 n=6
Emit Time 0.09s (± 0.00%) 0.09s (± 0.00%) ~ 0.09s 0.09s p=1.000 n=6
Total Time 8.84s (± 0.44%) 8.87s (± 0.28%) ~ 8.84s 8.90s p=0.127 n=6
Angular - node (v14.15.1, x64)
Memory used 355,248k (± 0.00%) 355,306k (± 0.01%) +58k (+ 0.02%) 355,248k 355,377k p=0.030 n=6
Parse Time 3.61s (± 0.45%) 3.59s (± 0.57%) ~ 3.57s 3.63s p=0.134 n=6
Bind Time 1.23s (± 0.42%) 1.22s (± 0.42%) ~ 1.22s 1.23s p=0.311 n=6
Check Time 9.81s (± 0.41%) 9.84s (± 0.47%) ~ 9.79s 9.93s p=0.295 n=6
Emit Time 8.32s (± 0.49%) 8.33s (± 0.42%) ~ 8.28s 8.37s p=0.870 n=6
Total Time 22.96s (± 0.29%) 22.98s (± 0.28%) ~ 22.88s 23.07s p=0.468 n=6
Compiler-Unions - node (v14.15.1, x64)
Memory used 187,820k (± 0.02%) 187,807k (± 0.02%) ~ 187,767k 187,863k p=0.471 n=6
Parse Time 1.60s (± 0.51%) 1.60s (± 0.73%) ~ 1.58s 1.61s p=0.738 n=6
Bind Time 0.84s (± 0.61%) 0.84s (± 0.65%) ~ 0.84s 0.85s p=0.640 n=6
Check Time 10.20s (± 0.59%) 10.22s (± 0.18%) ~ 10.20s 10.25s p=0.470 n=6
Emit Time 3.13s (± 1.52%) 3.12s (± 0.74%) ~ 3.10s 3.16s p=0.871 n=6
Total Time 15.77s (± 0.58%) 15.79s (± 0.20%) ~ 15.75s 15.83s p=1.000 n=6
Monaco - node (v14.15.1, x64)
Memory used 340,550k (± 0.00%) 340,570k (± 0.00%) +20k (+ 0.01%) 340,559k 340,580k p=0.037 n=6
Parse Time 2.82s (± 0.43%) 2.82s (± 0.69%) ~ 2.79s 2.84s p=0.391 n=6
Bind Time 1.10s (± 0.74%) 1.10s (± 0.37%) ~ 1.09s 1.10s p=0.218 n=6
Check Time 8.15s (± 0.46%) 8.14s (± 0.57%) ~ 8.09s 8.21s p=0.681 n=6
Emit Time 4.67s (± 0.54%) 4.66s (± 0.59%) ~ 4.62s 4.69s p=0.414 n=6
Total Time 16.75s (± 0.30%) 16.72s (± 0.38%) ~ 16.67s 16.83s p=0.332 n=6
TFS - node (v14.15.1, x64)
Memory used 294,891k (± 0.00%) 294,900k (± 0.00%) ~ 294,885k 294,912k p=0.199 n=6
Parse Time 2.38s (± 0.49%) 2.39s (± 0.89%) ~ 2.37s 2.42s p=0.511 n=6
Bind Time 1.06s (± 0.49%) 1.06s (± 0.38%) ~ 1.06s 1.07s p=0.595 n=6
Check Time 7.50s (± 0.68%) 7.50s (± 0.42%) ~ 7.44s 7.53s p=1.000 n=6
Emit Time 4.28s (± 0.39%) 4.28s (± 1.01%) ~ 4.22s 4.32s p=0.747 n=6
Total Time 15.23s (± 0.35%) 15.24s (± 0.36%) ~ 15.18s 15.33s p=0.747 n=6
material-ui - node (v14.15.1, x64)
Memory used 471,949k (± 0.00%) 471,972k (± 0.00%) ~ 471,951k 471,999k p=0.092 n=6
Parse Time 3.35s (± 0.52%) 3.35s (± 0.56%) ~ 3.32s 3.37s p=0.625 n=6
Bind Time 1.00s (± 1.03%) 1.01s (± 0.51%) ~ 1.00s 1.01s p=0.437 n=6
Check Time 19.07s (± 0.59%) 19.17s (± 0.49%) ~ 19.04s 19.27s p=0.199 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 23.43s (± 0.52%) 23.52s (± 0.47%) ~ 23.37s 23.64s p=0.334 n=6
xstate - node (v14.15.1, x64)
Memory used 539,166k (± 0.01%) 539,157k (± 0.01%) ~ 539,135k 539,206k p=0.470 n=6
Parse Time 4.23s (± 0.84%) 4.23s (± 0.77%) ~ 4.19s 4.27s p=1.000 n=6
Bind Time 1.66s (± 0.49%) 1.67s (± 0.70%) ~ 1.66s 1.69s p=0.271 n=6
Check Time 3.20s (± 0.76%) 3.19s (± 0.51%) ~ 3.18s 3.22s p=0.517 n=6
Emit Time 0.09s (± 0.00%) 0.09s (± 0.00%) ~ 0.09s 0.09s p=1.000 n=6
Total Time 9.19s (± 0.61%) 9.19s (± 0.57%) ~ 9.13s 9.25s p=0.873 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-135-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v18.10.0, x64)
  • node (v16.17.1, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v18.10.0, x64)
  • Angular - node (v16.17.1, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v18.10.0, x64)
  • Compiler-Unions - node (v16.17.1, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v18.10.0, x64)
  • Monaco - node (v16.17.1, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v18.10.0, x64)
  • TFS - node (v16.17.1, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v18.10.0, x64)
  • material-ui - node (v16.17.1, x64)
  • material-ui - node (v14.15.1, x64)
  • xstate - node (v18.10.0, x64)
  • xstate - node (v16.17.1, x64)
  • xstate - node (v14.15.1, x64)
Benchmark Name Iterations
Current 49863 6
Baseline main 6

TSServer

Comparison Report - main..49863
Metric main 49863 Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 2,393ms (± 0.39%) 2,402ms (± 0.35%) ~ 2,390ms 2,412ms p=0.172 n=6
Req 2 - geterr 5,420ms (± 0.18%) 5,418ms (± 0.40%) ~ 5,395ms 5,450ms p=0.810 n=6
Req 3 - references 342ms (± 1.06%) 341ms (± 0.90%) ~ 336ms 344ms p=0.746 n=6
Req 4 - navto 280ms (± 0.64%) 281ms (± 0.35%) ~ 279ms 282ms p=0.440 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 70ms (±10.40%) 67ms (± 0.61%) ~ 67ms 68ms p=0.528 n=6
CompilerTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 2,527ms (± 1.05%) 2,513ms (± 1.01%) ~ 2,480ms 2,550ms p=0.471 n=6
Req 2 - geterr 4,049ms (± 0.72%) 4,032ms (± 0.90%) ~ 4,000ms 4,091ms p=0.471 n=6
Req 3 - references 351ms (± 1.07%) 350ms (± 1.27%) ~ 344ms 355ms p=0.630 n=6
Req 4 - navto 293ms (± 0.40%) 294ms (± 0.47%) ~ 292ms 296ms p=0.310 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 82ms (± 2.98%) 81ms (± 3.35%) ~ 78ms 85ms p=0.624 n=6
xstateTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 3,008ms (± 0.44%) 3,005ms (± 0.55%) ~ 2,981ms 3,025ms p=0.873 n=6
Req 2 - geterr 1,596ms (± 0.64%) 1,596ms (± 0.74%) ~ 1,574ms 1,609ms p=1.000 n=6
Req 3 - references 107ms (± 0.84%) 107ms (± 0.70%) ~ 106ms 108ms p=0.798 n=6
Req 4 - navto 355ms (± 0.40%) 354ms (± 0.36%) ~ 353ms 356ms p=0.249 n=6
Req 5 - completionInfo count 2,861 (± 0.00%) 2,861 (± 0.00%) ~ 2,861 2,861 p=1.000 n=6
Req 5 - completionInfo 383ms (± 0.65%) 386ms (± 0.68%) ~ 383ms 390ms p=0.073 n=6
Compiler-UnionsTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,502ms (± 0.43%) 2,503ms (± 0.58%) ~ 2,492ms 2,532ms p=0.809 n=6
Req 2 - geterr 5,799ms (± 0.54%) 5,790ms (± 0.46%) ~ 5,755ms 5,832ms p=0.470 n=6
Req 3 - references 350ms (± 0.30%) 351ms (± 0.30%) ~ 349ms 352ms p=0.241 n=6
Req 4 - navto 278ms (± 1.08%) 274ms (± 0.78%) -4ms (- 1.56%) 272ms 278ms p=0.028 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 74ms (± 0.85%) 74ms (± 0.69%) ~ 74ms 75ms p=0.386 n=6
CompilerTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,680ms (± 0.69%) 2,674ms (± 0.47%) ~ 2,653ms 2,691ms p=0.297 n=6
Req 2 - geterr 4,394ms (± 0.35%) 4,398ms (± 0.31%) ~ 4,381ms 4,422ms p=0.521 n=6
Req 3 - references 358ms (± 0.61%) 358ms (± 0.49%) ~ 356ms 361ms p=1.000 n=6
Req 4 - navto 291ms (± 0.52%) 293ms (± 0.22%) +2ms (+ 0.80%) 292ms 294ms p=0.007 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 83ms (± 9.04%) 77ms (± 5.52%) ~ 75ms 86ms p=0.323 n=6
xstateTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 3,163ms (± 0.20%) 3,170ms (± 0.33%) ~ 3,159ms 3,187ms p=0.376 n=6
Req 2 - geterr 1,745ms (± 1.29%) 1,760ms (± 0.93%) ~ 1,741ms 1,780ms p=0.230 n=6
Req 3 - references 113ms (± 0.79%) 114ms (± 1.19%) ~ 113ms 116ms p=0.113 n=6
Req 4 - navto 340ms (± 0.42%) 339ms (± 0.40%) ~ 337ms 341ms p=0.511 n=6
Req 5 - completionInfo count 2,861 (± 0.00%) 2,861 (± 0.00%) ~ 2,861 2,861 p=1.000 n=6
Req 5 - completionInfo 396ms (± 0.91%) 396ms (± 0.84%) ~ 390ms 400ms p=1.000 n=6
Compiler-UnionsTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 2,602ms (± 0.36%) 2,600ms (± 0.39%) ~ 2,586ms 2,615ms p=0.575 n=6
Req 2 - geterr 6,191ms (± 0.51%) 6,181ms (± 0.58%) ~ 6,141ms 6,247ms p=0.378 n=6
Req 3 - references 363ms (± 0.59%) 366ms (± 0.66%) ~ 362ms 369ms p=0.124 n=6
Req 4 - navto 277ms (± 0.44%) 278ms (± 0.37%) ~ 276ms 279ms p=0.675 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 103ms (± 2.19%) 102ms (± 1.01%) ~ 100ms 103ms p=0.615 n=6
CompilerTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 2,811ms (± 1.11%) 2,820ms (± 0.72%) ~ 2,792ms 2,846ms p=0.688 n=6
Req 2 - geterr 4,576ms (± 2.09%) 4,605ms (± 2.74%) ~ 4,468ms 4,728ms p=0.748 n=6
Req 3 - references 382ms (± 5.01%) 389ms (± 7.68%) ~ 368ms 432ms p=0.809 n=6
Req 4 - navto 291ms (± 1.14%) 290ms (± 1.47%) ~ 286ms 298ms p=0.568 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 80ms (±10.02%) 82ms (±10.60%) ~ 73ms 93ms p=1.000 n=6
xstateTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 3,444ms (± 0.53%) 3,450ms (± 0.28%) ~ 3,437ms 3,464ms p=0.470 n=6
Req 2 - geterr 1,883ms (± 1.57%) 1,895ms (± 1.05%) ~ 1,875ms 1,932ms p=0.689 n=6
Req 3 - references 127ms (± 1.86%) 128ms (± 2.26%) ~ 125ms 133ms p=0.681 n=6
Req 4 - navto 369ms (± 0.30%) 371ms (± 0.50%) ~ 369ms 374ms p=0.099 n=6
Req 5 - completionInfo count 2,861 (± 0.00%) 2,861 (± 0.00%) ~ 2,861 2,861 p=1.000 n=6
Req 5 - completionInfo 411ms (± 0.75%) 413ms (± 1.50%) ~ 409ms 425ms p=0.807 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-135-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v18.10.0, x64)
  • node (v16.17.1, x64)
  • node (v14.15.1, x64)
Scenarios
  • Compiler-UnionsTSServer - node (v18.10.0, x64)
  • Compiler-UnionsTSServer - node (v16.17.1, x64)
  • Compiler-UnionsTSServer - node (v14.15.1, x64)
  • CompilerTSServer - node (v18.10.0, x64)
  • CompilerTSServer - node (v16.17.1, x64)
  • CompilerTSServer - node (v14.15.1, x64)
  • xstateTSServer - node (v18.10.0, x64)
  • xstateTSServer - node (v16.17.1, x64)
  • xstateTSServer - node (v14.15.1, x64)
Benchmark Name Iterations
Current 49863 6
Baseline main 6

Startup

Comparison Report - main..49863
Metric main 49863 Delta Best Worst p-value
tsc-startup - node (v16.17.1, x64)
Execution time 141.27ms (± 0.16%) 141.81ms (± 0.25%) +0.54ms (+ 0.38%) 140.47ms 146.45ms p=0.000 n=600
tsserver-startup - node (v16.17.1, x64)
Execution time 226.02ms (± 0.12%) 226.78ms (± 0.27%) +0.76ms (+ 0.33%) 225.00ms 232.91ms p=0.000 n=600
tsserverlibrary-startup - node (v16.17.1, x64)
Execution time 227.92ms (± 0.14%) 228.52ms (± 0.26%) +0.60ms (+ 0.26%) 226.84ms 233.38ms p=0.000 n=600
typescript-startup - node (v16.17.1, x64)
Execution time 208.90ms (± 0.18%) 209.37ms (± 0.27%) +0.47ms (+ 0.22%) 207.77ms 215.87ms p=0.000 n=600
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-135-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v16.17.1, x64)
Scenarios
  • tsc-startup - node (v16.17.1, x64)
  • tsserver-startup - node (v16.17.1, x64)
  • tsserverlibrary-startup - node (v16.17.1, x64)
  • typescript-startup - node (v16.17.1, x64)
Benchmark Name Iterations
Current 49863 6
Baseline main 6

Developer Information:

Download Benchmark

@typescript-bot
Copy link
Collaborator

Hey @DanielRosenwasser, the results of running the DT tests are ready.
There were interesting changes:

Branch only errors:

Package: regenerator-runtime
Error:

Error: /home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/DefinitelyTyped/types/regenerator-runtime/regenerator-runtime-tests.ts:28:1
ERROR: 28:1  expect  TypeScript@local expected type to be:
  (...args: [] | [any]) => Promise<IteratorResult<any, any>>
got:
  (...args: [] | [never]) => Promise<IteratorResult<unknown, unknown>>
ERROR: 29:1  expect  TypeScript@local expected type to be:
  (value: any) => Promise<IteratorResult<any, any>>
got:
  (value: unknown) => Promise<IteratorResult<unknown, unknown>>
ERROR: 30:1  expect  TypeScript@local expected type to be:
  (e: any) => Promise<IteratorResult<any, any>>
got:
  (e: any) => Promise<IteratorResult<unknown, unknown>>

    at testTypesVersion (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:194:15)
    at async runTests (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:151:9)

You can check the log here.

@typescript-bot
Copy link
Collaborator

@DanielRosenwasser Here are the results of running the top-repos suite comparing main and refs/pull/49863/merge:

Something interesting changed - please have a look.

Details

colinhacks/zod

4 of 5 projects failed to build with the old tsc and were ignored

tsconfig.cjs.json

  • error TS2345: Argument of type 'any[]' is not assignable to parameter of type '[] | [ZodTypeAny, ...ZodTypeAny[]]'.
  • error TS2322: Type 'unknown' is not assignable to type 'Primitive'.

jquense/yup

1 of 2 projects failed to build with the old tsc and were ignored

tsconfig.json

  • error TS2322: Type '{ <U extends unknown>(enums: readonly (Reference<unknown> | U)[], message?: Message<{ values: any; }> | undefined): Schema<unknown, unknown, unknown, Flags>; (enums: readonly unknown[], message: Message<{ values: any; }>): any; }' is not assignable to type '{ <U extends any>(enums: readonly (Reference<unknown> | U)[], message?: Message<{ values: any; }> | undefined): Schema<any, any, any, "">; (enums: readonly any[], message: Message<{ values: any; }>): any; }'.
  • error TS2322: Type '<U extends unknown>(enums: readonly (Reference<unknown> | Maybe<U>)[], message?: Message<{ values: any; }>) => Schema<unknown, unknown, unknown, Flags>' is not assignable to type '<U extends any>(enums: readonly (Reference<unknown> | Maybe<U>)[], message?: Message<{ values: any; }>) => Schema<any, any, any, "">'.

microsoft/vscode

4 of 53 projects failed to build with the old tsc and were ignored

src/tsconfig.monaco.json

src/tsconfig.tsec.json

ReactiveX/rxjs

8 of 13 projects failed to build with the old tsc and were ignored

src/tsconfig.cjs.spec.json

  • error TS2345: Argument of type 'Subscriber<T> | (Partial<Observer<T>> & Subscriber<never>) | (((value: T) => void) & Subscriber<never>)' is not assignable to parameter of type 'Subscriber<T>'.

src/tsconfig.esm5.rollup.json

  • error TS2345: Argument of type 'Subscriber<T> | (Partial<Observer<T>> & Subscriber<never>) | (((value: T) => void) & Subscriber<never>)' is not assignable to parameter of type 'Subscriber<T>'.

src/tsconfig.types.json

@typescript-bot
Copy link
Collaborator

@DanielRosenwasser Here are the results of running the top-repos suite comparing main and refs/pull/49863/merge:

Everything looks good!

@molisani
Copy link
Contributor Author

Following up on this. I saw some of the failures from the top-repos tests, but not sure how those should be interpreted. Most of the errors feel like correctly replacing a loose any with a strict unknown, but on the other hand it does feel quite strict.

If there's any conclusion that can be drawn from these results, or any further tests to be run, let me know if I can push this PR along in any way. Thanks!

@molisani
Copy link
Contributor Author

molisani commented Jun 9, 2023

Tested this out some more, and there might be a potential issue when a type parameter constraint refers to some other local type parameters (playground link)

declare class Box<T> { value: T }
declare class BoxBox<T, B extends Box<T>> { box: B }
declare const bb: any;
if (boxbox instanceof BoxBox) {
    bb; // BoxBox<unknown, Box<T>>
}

The new type of the class after the instanceof check is BoxBox<unknown, Box<T>>, but ideally it should be BoxBox<unknown, Box<unknown>>, right? Accessing bb.box.value returns a value with type T, but it doesn't seem like that should be allowed outside the context of the BoxBox definition.

I'll treat this as a bug for now and attempt to implement a solution.

@sandersn
Copy link
Member

sandersn commented Dec 5, 2023

@molisani @DanielRosenwasser @jakebailey It looks like this PR needs some fixes before it's ready. Do you want to keep working on it? Otherwise I like to close stale PRs after a few months.

@molisani
Copy link
Contributor Author

molisani commented Dec 5, 2023

It looks like this PR needs some fixes before it's ready. Do you want to keep working on it? Otherwise I like to close stale PRs after a few months.

It does need a few changes to make it ready. This slipped between the cracks and I should be able to get it back into shape soon.

@rbuckton
Copy link
Member

@molisani, have you had a chance to come back to this PR?

@molisani
Copy link
Contributor Author

I haven't, but I'm still optimistic that I'll be able to tackle this at some point. For now I'll close it out and if I can pick it up again I'll open a new PR with everything refreshed.

@molisani
Copy link
Contributor Author

molisani commented Apr 1, 2024

For anyone subscribed to this PR, I have recreated it with my latest comments resolved here: #58028

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