Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(57026): Renaming on declaration whose name is a String Literal #61353

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/services/findAllReferences.ts
Original file line number Diff line number Diff line change
@@ -1013,9 +1013,8 @@ export namespace Core {
const checker = program.getTypeChecker();
// constructors should use the class symbol, detected by name, if present
const symbol = checker.getSymbolAtLocation(isConstructorDeclaration(node) && node.parent.name || node);

// Could not find a symbol e.g. unknown identifier
if (!symbol) {
if (!symbol || (isStringLiteralLike(node) && isStringLiteralPropertyReference(node, checker))) {
// String literal might be a property (and thus have a symbol), so do this here rather than in getReferencedSymbolsSpecial.
if (!options.implementations && isStringLiteralLike(node)) {
if (isModuleSpecifierLike(node)) {
@@ -1389,7 +1388,6 @@ export namespace Core {
/** Only set if `options.implementations` is true. These are the symbols checked to get the implementations of a property access. */
readonly parents: readonly Symbol[] | undefined;
readonly allSearchSymbols: readonly Symbol[];

/**
* Whether a symbol is in the search set.
* Do not compare directly to `symbol` because there may be related symbols to search for. See `populateSearchSymbolSet`.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// === findRenameLocations ===
// === /tests/cases/fourslash/renameStringLiteralTypes5.ts ===
// type T = {
// <|"[|Prop 1RENAME|]": string;|>
// declare const Att_1: "[|Att 2RENAME|]"/*RENAME*/
//
// interface Case_1 {
// [Att_1]: string
// }
//
// declare const fn: <K extends keyof T>(p: K) => void
// declare const fnc_1: <K extends keyof Case_1>(p: K) => void
//
// fn("[|Prop 1RENAME|]"/*RENAME*/)
// fnc_1("[|Att 2RENAME|]")
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// === findRenameLocations ===
// === /tests/cases/fourslash/renameStringLiteralTypes6.ts ===
// interface Case_1 {
// <|"[|Att 2RENAME|]"/*RENAME*/: string|>
// }
//
// declare const fnc_1: <K extends keyof Case_1>(p: K) => void
//
// fnc_1("[|Att 2RENAME|]")
10 changes: 6 additions & 4 deletions tests/cases/fourslash/renameStringLiteralTypes5.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/// <reference path="fourslash.ts" />

////type T = {
//// "Prop 1": string;
////declare const Att_1: "Att 2"/**/
////
////interface Case_1 {
//// [Att_1]: string
////}
////
////declare const fn: <K extends keyof T>(p: K) => void
////declare const fnc_1: <K extends keyof Case_1>(p: K) => void
////
////fn("Prop 1"/**/)
////fnc_1("Att 2")

verify.baselineRename("", {});
12 changes: 12 additions & 0 deletions tests/cases/fourslash/renameStringLiteralTypes6.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference path="fourslash.ts" />


////interface Case_1 {
//// "Att 2"/**/: string
////}
////
////declare const fnc_1: <K extends keyof Case_1>(p: K) => void
////
////fnc_1("Att 2")

verify.baselineRename("", {});