From dbd55b3928cec8c571b0a55623e781535039f1cb Mon Sep 17 00:00:00 2001 From: Alexander T Date: Thu, 16 Jan 2020 02:56:40 +0200 Subject: [PATCH] fix(35944): show spell checking quick fix for non-existent private named property access (#36195) --- src/compiler/types.ts | 2 +- src/services/codefixes/fixSpelling.ts | 5 +++-- .../fourslash/codeFixSpellingPropertyAccess.ts | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/codeFixSpellingPropertyAccess.ts diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 98f2531b6c6..6102205a4d0 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3484,7 +3484,7 @@ namespace ts { */ /* @internal */ tryGetMemberInModuleExportsAndProperties(memberName: string, moduleSymbol: Symbol): Symbol | undefined; getApparentType(type: Type): Type; - /* @internal */ getSuggestionForNonexistentProperty(name: Identifier | string, containingType: Type): string | undefined; + /* @internal */ getSuggestionForNonexistentProperty(name: Identifier | PrivateIdentifier | string, containingType: Type): string | undefined; /* @internal */ getSuggestionForNonexistentSymbol(location: Node, name: string, meaning: SymbolFlags): string | undefined; /* @internal */ getSuggestionForNonexistentExport(node: Identifier, target: Symbol): string | undefined; getBaseConstraintOfType(type: Type): Type | undefined; diff --git a/src/services/codefixes/fixSpelling.ts b/src/services/codefixes/fixSpelling.ts index a2fa37b22fe..725237dd99e 100644 --- a/src/services/codefixes/fixSpelling.ts +++ b/src/services/codefixes/fixSpelling.ts @@ -36,12 +36,13 @@ namespace ts.codefix { let suggestion: string | undefined; if (isPropertyAccessExpression(node.parent) && node.parent.name === node) { - Debug.assert(node.kind === SyntaxKind.Identifier, "Expected an identifier for spelling (property access)"); + Debug.assert(isIdentifierOrPrivateIdentifier(node), "Expected an identifier for spelling (property access)"); let containingType = checker.getTypeAtLocation(node.parent.expression); if (node.parent.flags & NodeFlags.OptionalChain) { containingType = checker.getNonNullableType(containingType); } - suggestion = checker.getSuggestionForNonexistentProperty(node as Identifier, containingType); + const name = node as Identifier | PrivateIdentifier; + suggestion = checker.getSuggestionForNonexistentProperty(name, containingType); } else if (isImportSpecifier(node.parent) && node.parent.name === node) { Debug.assert(node.kind === SyntaxKind.Identifier, "Expected an identifier for spelling (import)"); diff --git a/tests/cases/fourslash/codeFixSpellingPropertyAccess.ts b/tests/cases/fourslash/codeFixSpellingPropertyAccess.ts new file mode 100644 index 00000000000..04ddb9a5caa --- /dev/null +++ b/tests/cases/fourslash/codeFixSpellingPropertyAccess.ts @@ -0,0 +1,17 @@ +/// + +////const foo = { +//// bar: 1 +////} +//// +////const bar = [|foo.#bar|]; + +verify.codeFixAvailable([ + { description: "Change spelling to 'bar'" }, +]); + +verify.codeFix({ + index: 0, + description: "Change spelling to 'bar'", + newRangeContent: "foo.bar" +});