From f45df8fb69aacc2d5a4065ca1de53dcea115dd09 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 29 Jun 2017 16:21:00 -0700 Subject: [PATCH] Spelling code fix:suggestions from apparent type 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 --- src/services/codefixes/fixSpelling.ts | 2 +- tests/cases/fourslash/codeFixCorrectSpelling.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/codeFixCorrectSpelling.ts diff --git a/src/services/codefixes/fixSpelling.ts b/src/services/codefixes/fixSpelling.ts index c8f539e8d34..d632671f6ee 100644 --- a/src/services/codefixes/fixSpelling.ts +++ b/src/services/codefixes/fixSpelling.ts @@ -16,7 +16,7 @@ namespace ts.codefix { const checker = context.program.getTypeChecker(); let suggestion: string; if (node.kind === SyntaxKind.Identifier && isPropertyAccessExpression(node.parent)) { - const containingType = checker.getTypeAtLocation(node.parent.expression); + const containingType = checker.getApparentType(checker.getTypeAtLocation(node.parent.expression)); suggestion = checker.getSuggestionForNonexistentProperty(node as Identifier, containingType); } else { diff --git a/tests/cases/fourslash/codeFixCorrectSpelling.ts b/tests/cases/fourslash/codeFixCorrectSpelling.ts new file mode 100644 index 00000000000..4294e6e44df --- /dev/null +++ b/tests/cases/fourslash/codeFixCorrectSpelling.ts @@ -0,0 +1,15 @@ +/// + +////[|class C { +//// state = 'hi' +//// doStuff() { +//// this.start; +//// } +////}|] + +verify.rangeAfterCodeFix(`class C { + state = 'hi' + doStuff() { + this.state; + } +}`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 2);