Skip to content

Commit dbd55b3

Browse files
a-tarasyuksandersn
authored andcommitted
fix(35944): show spell checking quick fix for non-existent private named property access (#36195)
1 parent f990725 commit dbd55b3

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3484,7 +3484,7 @@ namespace ts {
34843484
*/
34853485
/* @internal */ tryGetMemberInModuleExportsAndProperties(memberName: string, moduleSymbol: Symbol): Symbol | undefined;
34863486
getApparentType(type: Type): Type;
3487-
/* @internal */ getSuggestionForNonexistentProperty(name: Identifier | string, containingType: Type): string | undefined;
3487+
/* @internal */ getSuggestionForNonexistentProperty(name: Identifier | PrivateIdentifier | string, containingType: Type): string | undefined;
34883488
/* @internal */ getSuggestionForNonexistentSymbol(location: Node, name: string, meaning: SymbolFlags): string | undefined;
34893489
/* @internal */ getSuggestionForNonexistentExport(node: Identifier, target: Symbol): string | undefined;
34903490
getBaseConstraintOfType(type: Type): Type | undefined;

src/services/codefixes/fixSpelling.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ namespace ts.codefix {
3636

3737
let suggestion: string | undefined;
3838
if (isPropertyAccessExpression(node.parent) && node.parent.name === node) {
39-
Debug.assert(node.kind === SyntaxKind.Identifier, "Expected an identifier for spelling (property access)");
39+
Debug.assert(isIdentifierOrPrivateIdentifier(node), "Expected an identifier for spelling (property access)");
4040
let containingType = checker.getTypeAtLocation(node.parent.expression);
4141
if (node.parent.flags & NodeFlags.OptionalChain) {
4242
containingType = checker.getNonNullableType(containingType);
4343
}
44-
suggestion = checker.getSuggestionForNonexistentProperty(node as Identifier, containingType);
44+
const name = node as Identifier | PrivateIdentifier;
45+
suggestion = checker.getSuggestionForNonexistentProperty(name, containingType);
4546
}
4647
else if (isImportSpecifier(node.parent) && node.parent.name === node) {
4748
Debug.assert(node.kind === SyntaxKind.Identifier, "Expected an identifier for spelling (import)");
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////const foo = {
4+
//// bar: 1
5+
////}
6+
////
7+
////const bar = [|foo.#bar|];
8+
9+
verify.codeFixAvailable([
10+
{ description: "Change spelling to 'bar'" },
11+
]);
12+
13+
verify.codeFix({
14+
index: 0,
15+
description: "Change spelling to 'bar'",
16+
newRangeContent: "foo.bar"
17+
});

0 commit comments

Comments
 (0)