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

Fixed inferred const rest types in signatures #55034

Conversation

Andarist
Copy link
Contributor

fixes #55033

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jul 15, 2023
@ssalbdivad
Copy link

ssalbdivad commented Jul 16, 2023

Pretty hyped for this one. I've run into so many issues trying to constrain narrowed array types without breaking inference. Couldn't really tell from the linked issue if this will fix a lot of them, but I have faith 🙏

@jakebailey
Copy link
Member

After messing with this same code for #53255, #53258 (note a similar getRestTypeAtPosition change), #53398, I'm like 50% afraid of this 😄

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 18, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 18, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 18, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 18, 2023

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 18, 2023

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 18, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 18, 2023

Hey @jakebailey, 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/155902/artifacts?artifactName=tgz&fileId=FAE8E38594F6A90F7E599497909CC324A2C4C0E435E4CFA4BD738E7304C0DB8F02&fileName=/typescript-5.2.0-insiders.20230718.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]".;

@Andarist
Copy link
Contributor Author

After messing with this same code for #53255, #53258 (note a similar getRestTypeAtPosition change), #53398, I'm like 50% afraid of this 😄

When learning about this issue I immediately opened your PR to check out if it's related anyhow to this issue. I think that at the end of the day, it isn't and that this PR shouldn't actually impact anybody negatively. This only makes those rests readonly when the type variable is const - given that const is pretty new I don't expect any accidental breakage here.

@jakebailey
Copy link
Member

After messing with this same code for #53255, #53258 (note a similar getRestTypeAtPosition change), #53398, I'm like 50% afraid of this 😄

When learning about this issue I immediately opened your PR to check out if it's related anyhow to this issue. I think that at the end of the day, it isn't and that this PR shouldn't actually impact anybody negatively. This only makes those rests readonly when the type variable is const - given that const is pretty new I don't expect any accidental breakage here.

Yeah, I'm pretty sure that I was a little overzealous in propagating readonly to the last use (this PR), where my issue was definitely intended to change the other use.

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - main..55034

Metric main 55034 Delta Best Worst p-value
Angular - node (v16.17.1, x64)
Memory used 366,223k (± 0.01%) 366,214k (± 0.00%) ~ 366,200k 366,225k p=0.423 n=6
Parse Time 3.56s (± 0.65%) 3.58s (± 0.63%) ~ 3.56s 3.62s p=0.168 n=6
Bind Time 1.19s (± 0.63%) 1.20s (± 0.46%) ~ 1.19s 1.20s p=0.137 n=6
Check Time 9.71s (± 0.46%) 9.67s (± 0.42%) ~ 9.62s 9.73s p=0.146 n=6
Emit Time 8.09s (± 0.46%) 8.02s (± 0.77%) ~ 7.96s 8.12s p=0.065 n=6
Total Time 22.54s (± 0.28%) 22.46s (± 0.43%) ~ 22.37s 22.63s p=0.126 n=6
Compiler-Unions - node (v16.17.1, x64)
Memory used 193,442k (± 0.68%) 193,464k (± 0.68%) ~ 192,849k 196,148k p=0.471 n=6
Parse Time 1.59s (± 0.51%) 1.59s (± 0.62%) ~ 1.57s 1.60s p=0.383 n=6
Bind Time 0.83s (± 0.66%) 0.82s (± 0.92%) ~ 0.81s 0.83s p=0.137 n=6
Check Time 10.15s (± 0.76%) 10.18s (± 0.56%) ~ 10.11s 10.28s p=0.378 n=6
Emit Time 3.00s (± 0.53%) 3.01s (± 1.35%) ~ 2.98s 3.09s p=1.000 n=6
Total Time 15.56s (± 0.54%) 15.60s (± 0.54%) ~ 15.51s 15.76s p=0.378 n=6
Monaco - node (v16.17.1, x64)
Memory used 346,183k (± 0.01%) 346,189k (± 0.00%) ~ 346,176k 346,200k p=0.689 n=6
Parse Time 2.77s (± 0.49%) 2.78s (± 0.77%) ~ 2.76s 2.82s p=0.742 n=6
Bind Time 1.07s (± 0.38%) 1.08s (± 0.59%) +0.01s (+ 1.09%) 1.07s 1.09s p=0.009 n=6
Check Time 8.01s (± 0.67%) 8.03s (± 0.45%) ~ 7.98s 8.07s p=0.687 n=6
Emit Time 4.49s (± 0.60%) 4.47s (± 0.86%) ~ 4.44s 4.54s p=0.332 n=6
Total Time 16.34s (± 0.50%) 16.35s (± 0.41%) ~ 16.27s 16.45s p=0.872 n=6
TFS - node (v16.17.1, x64)
Memory used 300,246k (± 0.00%) 300,229k (± 0.01%) ~ 300,203k 300,252k p=0.128 n=6
Parse Time 2.21s (± 0.62%) 2.21s (± 0.72%) ~ 2.19s 2.23s p=0.869 n=6
Bind Time 1.20s (± 1.33%) 1.21s (± 0.81%) ~ 1.19s 1.22s p=0.510 n=6
Check Time 7.33s (± 0.45%) 7.34s (± 0.34%) ~ 7.30s 7.37s p=0.618 n=6
Emit Time 4.35s (± 0.52%) 4.33s (± 1.25%) ~ 4.26s 4.42s p=0.145 n=6
Total Time 15.09s (± 0.33%) 15.08s (± 0.37%) ~ 15.01s 15.14s p=0.574 n=6
material-ui - node (v16.17.1, x64)
Memory used 481,657k (± 0.01%) 481,630k (± 0.01%) ~ 481,584k 481,695k p=0.575 n=6
Parse Time 3.25s (± 0.41%) 3.27s (± 0.57%) +0.02s (+ 0.46%) 3.23s 3.28s p=0.048 n=6
Bind Time 0.96s (± 0.78%) 0.96s (± 1.26%) ~ 0.95s 0.98s p=0.235 n=6
Check Time 18.45s (± 0.60%) 18.36s (± 0.58%) ~ 18.28s 18.57s 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 22.67s (± 0.46%) 22.58s (± 0.52%) ~ 22.47s 22.81s p=0.199 n=6
xstate - node (v16.17.1, x64)
Memory used 561,367k (± 0.03%) 561,174k (± 0.02%) -193k (- 0.03%) 561,060k 561,346k p=0.031 n=6
Parse Time 4.00s (± 0.34%) 4.03s (± 0.43%) +0.02s (+ 0.54%) 4.01s 4.06s p=0.042 n=6
Bind Time 1.78s (± 1.05%) 1.79s (± 1.22%) ~ 1.77s 1.83s p=0.505 n=6
Check Time 3.07s (± 0.39%) 3.06s (± 0.68%) ~ 3.04s 3.09s p=0.514 n=6
Emit Time 0.10s (± 5.76%) 0.10s (± 5.76%) ~ 0.09s 0.10s p=1.000 n=6
Total Time 8.94s (± 0.39%) 8.97s (± 0.44%) ~ 8.92s 9.03s p=0.228 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-148-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
  • Angular - node (v16.17.1, x64)
  • Compiler-Unions - node (v16.17.1, x64)
  • Monaco - node (v16.17.1, x64)
  • TFS - node (v16.17.1, x64)
  • material-ui - node (v16.17.1, x64)
  • xstate - node (v16.17.1, x64)
Benchmark Name Iterations
Current 55034 6
Baseline main 6

Developer Information:

Download Benchmark

@typescript-bot
Copy link
Collaborator

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

There were infrastructure failures potentially unrelated to your change:

  • 1 instance of "Unknown failure"
  • 1 instance of "Package install failed"

Otherwise...

Something interesting changed - please have a look.

Details

rxjs-src

/mnt/ts_downloads/rxjs-src/build.sh

  • [NEW] error TS2428: All declarations of 'WeakMap' must have identical type parameters.
    • /home/vsts/work/1/s/typescript-55034/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-55034/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55034/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-55034/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-55034/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55034/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-55034/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-55034/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55034/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-55034/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-55034/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55034/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-55034/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-55034/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55034/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
  • [MISSING] error TS2428: All declarations of 'WeakMap' must have identical type parameters.
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@typescript-bot
Copy link
Collaborator

Hey @jakebailey, the results of running the DT tests are ready.
Everything looks the same!
You can check the log here.

@sandersn sandersn self-assigned this Jul 28, 2023
@sandersn
Copy link
Member

The bug is marked Working As Intended now, so should we close this PR?

@Andarist
Copy link
Contributor Author

The reported issue had some issues in it (it didnt use a readonly constraint). So im not sure if „working as intended” was applied to only what was oroginally reported or if it was applied to everything that was discussed there. I think that this particular thing that I fixed here still has some merit so i’d appreciate if this would get reviewed

@ahejlsberg
Copy link
Member

I like where this is going, but I think we also need the changes in #55229. For example, the following is broken by this PR without the additional changes:

declare function invoke<const T extends unknown[]>(f: (...args: T) => void, ...args: T): T;

invoke((a: string, b: number) => {}, "hello", 123);

I know this isn't a particularly likely break, but the inference failure because of non-readonly constraints is just confounding to most users and hard to justify (even if I've tried).

@Andarist
Copy link
Contributor Author

Andarist commented Aug 1, 2023

I know this isn't a particularly likely break, but the inference failure because of non-readonly constraints is just confounding to most users and hard to justify (even if I've tried).

ye, this tends to be pretty confusing - would it be worth adding some diagnostics that would prompt users to add the reaodnly modifier to their constraints? Might not be feasible when constraints are defined using aliases but catching common cases when they are declared directly in the signature could still help a lot

@ahejlsberg
Copy link
Member

would it be worth adding some diagnostics that would prompt users to add the reaodnly modifier to their constraints?

I'm hoping there's no need for that with #55229 since inference now adjusts itself based on constraints.

@Andarist
Copy link
Contributor Author

Closing as those commits are now included in #55229

@Andarist Andarist closed this Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Type hole: A function with const generic does not infer the type if it is a spread parameter (tuple)
6 participants