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);