Open devanshj opened 2 years ago
I sort of thought this did work, at least in simple cases, but looks like we never consider string literals for rename/references with keyof
? Super simple example:
interface A {
a: string;
}
declare function f(a: A, k: keyof A): void;
declare let a: A;
f(a, "a");
I think I’d expect these to work, but wouldn’t be surprised if it’s complicated/expensive.
Labeled for Effort: Moderately Difficult?
FWIW, I think getting my example to work would be a win, and would probably fix the f2
test case. f3
may be more difficult, and a PR that doesn’t fix f3
would still be acceptable.
I was surprised you marked it as "bug" but then realized it indeed is a bug -- as the renaming refactor produces a compile error! xD
I’m calling it a bug because #5602 was marked as fixed. There are also #41489, #41923, and #41922 which are related.
Suggestion
🔍 Search Terms
rename string literals, refactor
✅ Viability Checklist
⭐ Suggestion
Playground for code below
📃 Motivating Example
A bunch of popular libraries that will benefit from this for example...
1. xstate
This feature will enable ctrl+click on "doStuff" in index.tsx navigating to "doStuff" in machine.ts and renaming both "doStuff" by renaming either of them (given the types are correct ofc)
2. stitches
Taken from here
Here the string literal
"violet"
in<Button color="violet">Button</Button>
references theviolet
key in the object passed tostyled
function3. framer-motion
Taken from here
Here the string literals
"open"
and"close"
inmotion.nav
'sanimate
reference the keys ofvariants
passed to it.These three come to my mind right now, but I think this is a very common pattern so the improvement in the intellisense will have a significant impact.