Skip to content

Commit 02453a0

Browse files
a-tarasyuksandersn
andauthored
fix(56052): Rename Symbol F2 with "pure keyof" is not possible - but it is possible if "wrapped as calculated property" (#56061)
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
1 parent ef6ac03 commit 02453a0

5 files changed

+48
-1
lines changed

src/services/findAllReferences.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ import {
163163
isParameterPropertyDeclaration,
164164
isPrivateIdentifierClassElementDeclaration,
165165
isPropertyAccessExpression,
166+
isPropertySignature,
166167
isQualifiedName,
167168
isReferencedFile,
168169
isReferenceFileLocation,
@@ -2471,7 +2472,7 @@ export namespace Core {
24712472
if (isStringLiteralLike(ref) && ref.text === node.text) {
24722473
if (type) {
24732474
const refType = getContextualTypeFromParentOrAncestorTypeNode(ref, checker);
2474-
if (type !== checker.getStringType() && type === refType) {
2475+
if (type !== checker.getStringType() && (type === refType || isStringLiteralPropertyReference(ref, checker))) {
24752476
return nodeEntry(ref, EntryKind.StringLiteral);
24762477
}
24772478
}
@@ -2489,6 +2490,12 @@ export namespace Core {
24892490
}];
24902491
}
24912492

2493+
function isStringLiteralPropertyReference(node: StringLiteralLike, checker: TypeChecker) {
2494+
if (isPropertySignature(node.parent)) {
2495+
return checker.getPropertyOfType(checker.getTypeAtLocation(node.parent.parent), node.text);
2496+
}
2497+
}
2498+
24922499
// For certain symbol kinds, we need to include other symbols in the search set.
24932500
// This is not needed when searching for re-exports.
24942501
function populateSearchSymbolSet(symbol: Symbol, location: Node, checker: TypeChecker, isForRename: boolean, providePrefixAndSuffixText: boolean, implementations: boolean): Symbol[] {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// === findRenameLocations ===
2+
// === /tests/cases/fourslash/renameStringLiteralTypes4.ts ===
3+
// interface I {
4+
// <|"[|Prop 1RENAME|]": string;|>
5+
// }
6+
//
7+
// declare const fn: <K extends keyof I>(p: K) => void
8+
//
9+
// fn("[|Prop 1RENAME|]"/*RENAME*/)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// === findRenameLocations ===
2+
// === /tests/cases/fourslash/renameStringLiteralTypes5.ts ===
3+
// type T = {
4+
// <|"[|Prop 1RENAME|]": string;|>
5+
// }
6+
//
7+
// declare const fn: <K extends keyof T>(p: K) => void
8+
//
9+
// fn("[|Prop 1RENAME|]"/*RENAME*/)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////interface I {
4+
//// "Prop 1": string;
5+
////}
6+
////
7+
////declare const fn: <K extends keyof I>(p: K) => void
8+
////
9+
////fn("Prop 1"/**/)
10+
11+
verify.baselineRename("", {});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////type T = {
4+
//// "Prop 1": string;
5+
////}
6+
////
7+
////declare const fn: <K extends keyof T>(p: K) => void
8+
////
9+
////fn("Prop 1"/**/)
10+
11+
verify.baselineRename("", {});

0 commit comments

Comments
 (0)