-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Expand constraint suggestion related span and add quick fix #49481
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
Expand constraint suggestion related span and add quick fix #49481
Conversation
@typescript-bot pack this |
Heya @RyanCavanaugh, I've started to run the tarball bundle task on this PR at 00ef5ae. You can monitor the build here. |
Hey @RyanCavanaugh, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
Most of the breaks I saw looked like this, which currently isn't quickfixable. Can we expand it? interface Fn<T extends string> {
}
function m<T>(x: Fn<T>) {
} |
Sure, should be easy - just another error code in the quickfix hopefully, since it uses a custom head message on the assignability error. |
@RyanCavanaugh done. There are a lot of custom head messages for relation errors, and thus, many error codes we could conceivably add to this quickfix. I don't claim the current list to be exhaustive, just the ones I read in the core |
@typescript-bot pack this |
Heya @RyanCavanaugh, I've started to run the tarball bundle task on this PR at d70dc0a. You can monitor the build here. |
Hey @RyanCavanaugh, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
(This isn’t the first time it would have been nice to be able to register a codefix against a related error instead of the head message.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep an eye out for how often the related diagnostic / quick fix is the correct fix in real world code since it seems to be showing up a lot more often.
It's any time you assign an unconstrained type parameter to something, so potentially pretty often. Conversely, it's probably got a pretty high success rate, I think. The other way you'd have to take the fix is changing the target type's position to |
Notably, that failure mode does imply another, narrower, potentially useful quickfix - if a constrained type parameter fails being related to some target type, suggesting the target type be intersected into the constraint of the source type parameter is potentially a good fix. Unfortunately, a large corpus of code with errors isn't exactly something we have to know how useful such a fix would be. |
This expands the originally very narrow elaboration to be reported any time an unconstrained type parameter is related to something, and adds a quickfix to apply the change.