Skip to content

Spelling code fix: suggestions from apparent type #16844

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

Merged
merged 3 commits into from
Jun 30, 2017

Conversation

sandersn
Copy link
Member

The code fix for spelling correction needs to provide suggestions based on the apparent type since sometimes the type at a location will be a type parameter. One such example is this.

Fixes #16744

The code fix for spelling correction needs to provide suggestions based
on the apparent type since sometimes the type at a location will be a type
parameter. One such example is `this`.

Fixes #16744
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jun 30, 2017

Can you add tests for primitives (e.g. localCompare vs localeCompare on string), as well as tests for something with a constraint such as the following?

function foo<T extends number | string>(x: T) {
  return x.toStrang();
}

@sandersn
Copy link
Member Author

Turns out suggestions don't work at compile-time on non-object types. That's kind of a separate bug, but simple enough to fix, so I'll just fix it here.

sandersn added 2 commits June 30, 2017 10:11
This provides suggestions for more types based on their apparent type:
unions, type parameters with constraints, primitives.
Test spelling suggestions for primitives, unions/intersections and type
parameters with constraints.
@@ -87,7 +87,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio
function fn5() { return undefined; }
fn5 `${ (n) => n.toFixed() }`; // will error; 'n' should have type 'string'.
~~~~~~~
!!! error TS2339: Property 'toFixed' does not exist on type 'string'.
!!! error TS2551: Property 'toFixed' does not exist on type 'string'. Did you mean 'fixed'?
Copy link
Member Author

Choose a reason for hiding this comment

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

this looks weird until you look up fixed and find out that it's actually a deprecated member of String.

@sandersn sandersn merged commit 9048c0a into master Jun 30, 2017
@sandersn sandersn deleted the codefix-spelling-correction-for-typeparameters branch June 30, 2017 19:56
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Misspelled 'this.' property accesses don't trigger spelling correction fixes
4 participants