typescript-language-server / typescript-language-server

TypeScript & JavaScript Language Server

Home Page:https://www.npmjs.com/package/typescript-language-server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rename Symbol F2 with "pure keyof" is not possible - but it is possible if "wrapped as calculated property"

qwertysk opened this issue ยท comments

I think this could be related to typescript-language-server, even I reported it also here microsoft/TypeScript#56052

๐Ÿ”Ž Search Terms

Rename symbol, keyof

๐Ÿ•— Version & Regression Information

  • This is the behavior in every version I tried

โฏ Playground Link

https://tsplay.dev/N7QgPW

๐Ÿ’ป Code

////////////////////////// CASE 1 - keyof to computed property /////////////////////////

declare const Att_1: "Att 1"

interface Case_1 {
  [Att_1]: string
}

declare const fnc_1: <K extends keyof Case_1>(p: K) => void

fnc_1("Att 1")
//     ^_ Rename Symbol F2 => SUCCESS



////////////////////////// CASE 2 - pure keyof //////////////////////////

interface Case_2 {
  "Att 2": string // here is the difference, pls compare to Case_1
}

declare const fnc_2: <K extends keyof Case_2>(p: K) => void

fnc_2("Att 2")
//     ^_ Rename Symbol F2 => FAIL

๐Ÿ™ Actual behavior

image

It is wrong because Att 2 in interface Case_2 is not renamed

๐Ÿ™‚ Expected behavior

I expect Att 2 in interface Case_2 to be successfully renamed to Attribute 2

Additional information about the issue

Even it is not "a bug but the feature", is there best practice - if reliable renaming is really frequent and important in my project ?

PLS HELP ME โค๏ธโค๏ธโค๏ธ ... because manually create tons of constants for all project interfaces and all attributes - this is not maintanable way - any other ideas/patterns please ?

I think an issue in Typescript is enough since the logic for renaming is all there.