diff --git a/src/services/codefixes/fixSpelling.ts b/src/services/codefixes/fixSpelling.ts index c8f539e8d347e..ff3bd455291e2 100644 --- a/src/services/codefixes/fixSpelling.ts +++ b/src/services/codefixes/fixSpelling.ts @@ -15,7 +15,8 @@ namespace ts.codefix { const node = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false); // TODO: GH#15852 const checker = context.program.getTypeChecker(); let suggestion: string; - if (node.kind === SyntaxKind.Identifier && isPropertyAccessExpression(node.parent)) { + if (isPropertyAccessExpression(node.parent) && node.parent.name === node) { + Debug.assert(node.kind === SyntaxKind.Identifier); const containingType = checker.getTypeAtLocation(node.parent.expression); suggestion = checker.getSuggestionForNonexistentProperty(node as Identifier, containingType); } diff --git a/tests/cases/fourslash/codeFixCorrectSpelling4.ts b/tests/cases/fourslash/codeFixCorrectSpelling4.ts new file mode 100644 index 0000000000000..21dd3f03a1d24 --- /dev/null +++ b/tests/cases/fourslash/codeFixCorrectSpelling4.ts @@ -0,0 +1,7 @@ +/// + +//// export declare const despite: { the: any }; +//// +//// [|dispite.the|] + +verify.rangeAfterCodeFix(`despite.the`);