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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14504,7 +14504,7 @@ namespace ts {
}

function getSuggestionForNonexistentProperty(node: Identifier, containingType: Type): string | undefined {
const suggestion = getSpellingSuggestionForName(node.text, getPropertiesOfObjectType(containingType), SymbolFlags.Value);
const suggestion = getSpellingSuggestionForName(node.text, getPropertiesOfType(containingType), SymbolFlags.Value);
return suggestion && suggestion.name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio
tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3_ES6.ts(44,1): error TS2554: Expected 2-4 arguments, but got 1.
tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3_ES6.ts(62,9): error TS2345: Argument of type 'true' is not assignable to parameter of type 'number'.
tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3_ES6.ts(63,18): error TS2345: Argument of type 'true' is not assignable to parameter of type 'string'.
tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3_ES6.ts(69,18): error TS2339: Property 'toFixed' does not exist on type 'string'.
tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3_ES6.ts(69,18): error TS2551: Property 'toFixed' does not exist on type 'string'. Did you mean 'fixed'?


==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3_ES6.ts (6 errors) ====
Expand Down Expand Up @@ -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.

fn5 `${ (n) => n.substr(0) }`;


Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/jsx/file.tsx(19,16): error TS2559: Type '{ ref: "myRef"; }' has no properties in common with type 'IntrinsicAttributes & { name?: string; }'.
tests/cases/conformance/jsx/file.tsx(25,42): error TS2339: Property 'subtr' does not exist on type 'string'.
tests/cases/conformance/jsx/file.tsx(25,42): error TS2551: Property 'subtr' does not exist on type 'string'. Did you mean 'substr'?
tests/cases/conformance/jsx/file.tsx(27,33): error TS2339: Property 'notARealProperty' does not exist on type 'BigGreeter'.
tests/cases/conformance/jsx/file.tsx(35,26): error TS2339: Property 'propertyNotOnHtmlDivElement' does not exist on type 'HTMLDivElement'.

Expand Down Expand Up @@ -33,7 +33,7 @@ tests/cases/conformance/jsx/file.tsx(35,26): error TS2339: Property 'propertyNot
// Error ('subtr' not on string)
let e = <BigGreeter ref={x => x.greeting.subtr(10)} />;
~~~~~
!!! error TS2339: Property 'subtr' does not exist on type 'string'.
!!! error TS2551: Property 'subtr' does not exist on type 'string'. Did you mean 'substr'?
// Error (ref callback is contextually typed)
let f = <BigGreeter ref={x => x.notARealProperty} />;
~~~~~~~~~~~~~~~~
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/unionPropertyExistence.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tests/cases/compiler/unionPropertyExistence.ts(32,4): error TS2339: Property 'on
Property 'onlyInB' does not exist on type 'A'.
tests/cases/compiler/unionPropertyExistence.ts(35,5): error TS2339: Property 'notInC' does not exist on type 'ABC'.
Property 'notInC' does not exist on type 'C'.
tests/cases/compiler/unionPropertyExistence.ts(36,4): error TS2339: Property 'notInB' does not exist on type 'AB'.
tests/cases/compiler/unionPropertyExistence.ts(36,4): error TS2551: Property 'notInB' does not exist on type 'AB'. Did you mean 'notInC'?
Property 'notInB' does not exist on type 'B'.
tests/cases/compiler/unionPropertyExistence.ts(37,5): error TS2339: Property 'notInB' does not exist on type 'ABC'.
Property 'notInB' does not exist on type 'B'.
Expand Down Expand Up @@ -69,8 +69,8 @@ tests/cases/compiler/unionPropertyExistence.ts(40,5): error TS2339: Property 'in
!!! error TS2339: Property 'notInC' does not exist on type 'C'.
ab.notInB;
~~~~~~
!!! error TS2339: Property 'notInB' does not exist on type 'AB'.
!!! error TS2339: Property 'notInB' does not exist on type 'B'.
!!! error TS2551: Property 'notInB' does not exist on type 'AB'. Did you mean 'notInC'?
!!! error TS2551: Property 'notInB' does not exist on type 'B'.
abc.notInB;
~~~~~~
!!! error TS2339: Property 'notInB' does not exist on type 'ABC'.
Expand Down
9 changes: 9 additions & 0 deletions tests/cases/fourslash/codeFixCorrectSpelling1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />

////[|function foo(s: string) {
//// return s.toStrang();
////}|]

verify.rangeAfterCodeFix(`function foo(s: string) {
return s.toString();
}`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 0);
9 changes: 9 additions & 0 deletions tests/cases/fourslash/codeFixCorrectSpelling2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />

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

verify.rangeAfterCodeFix(`function foo<T extends number | string>(x: T) {
return x.toString();
}`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 0);
15 changes: 15 additions & 0 deletions tests/cases/fourslash/codeFixCorrectSpelling3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference path='fourslash.ts' />

////[|class C {
//// state = 'hi'
//// doStuff() {
//// this.start;
//// }
////}|]

verify.rangeAfterCodeFix(`class C {
state = 'hi'
doStuff() {
this.state;
}
}`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 2);