You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Key remapping breaks definition navigation for mapped type properties #47813
When using mapped type with key remapping, definitions for the properties of mapped types are no longer discoverable. Though, references are still in there.
🔎 Search Terms
mapped types, key remapping, language server, editor hints
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about mapped types
constobject={a: 1,// ✅ can go to definition/references, can renameb: 2,// ✅ can go to definition/references, can renamec: 'ok',// ✅ no references, can rename};/** ✅ rename of {@link object.a} and {@link object.b} will correctly rename all the references as well */constremapByKey: {[PinkeyoftypeofobjectasPextends'c' ? never : P]: 0;}={a: 0,b: 0};remapByKey.a;// ❌ can't go to definition, can't rename, ✅ yet highlights definitionremapByKey.b;// ❌ can't go to definition, can't rename, ✅ yet highlights definitionremapByKey.c;// ✅ errors as expectedconstremapByValue: {[Pinkeyoftypeofobjectastypeofobject[P]extendsstring ? never : P]: 0;}={a: 0,b: 0};remapByValue.a;// ❌ can't go to definition, can't rename, ✅ yet highlights definitionremapByValue.b;// ❌ can't go to definition, can't rename, ✅ yet highlights definitionremapByValue.c;// ✅ errors as expected
🙁 Actual behavior
🙂 Expected behavior
Capability to navigate to definition of remapped property.
What about the capability to go to definition? In remapped type you can go to reference from any reference or definition point. But you can't go to definition from a reference.
Contrary, in a mapped type without remapping, you can go back and forth between definition and reference, in both directions.
I encountered a case where this nearly works, which makes me wonder if there's a worthwhile partial fix.
When I use key remapping on a record of functions, the functions can be found once I add parens. "Go to type definition" in VSCode works with and without parens.
constfuncs={foo: ()=>{},bar: ()=>{}}constc={}as{[KinkeyoftypeoffuncsasK]: typeoffuncs[K]}c.foo// doesn't cmd-click (known, that's this issue #47813) but "go to type definition" works (VSCode)c.foo()// cmd-click works fine!
Activity
RyanCavanaugh commentedon Feb 9, 2022
The highlighting you see is purely syntactic; unrelated instances of
awill also highlight for example.ayatkevich commentedon Feb 10, 2022
Ryan Cavanaugh (@RyanCavanaugh) ah, I see.
What about the capability to go to definition? In remapped type you can go to reference from any reference or definition point. But you can't go to definition from a reference.
Contrary, in a mapped type without remapping, you can go back and forth between definition and reference, in both directions.
RyanCavanaugh commentedon Feb 10, 2022
It definitely "should" work, but it's a bit tricky to implement AFAIR
sfedorov-at-wiley commentedon Apr 2, 2022
Still does not work

But it definitely will be nice to make a hint for IDE, that mapped key refers to corresponding key in given object
thomasballinger commentedon Sep 28, 2022
I encountered a case where this nearly works, which makes me wonder if there's a worthwhile partial fix.
When I use key remapping on a record of functions, the functions can be found once I add parens. "Go to type definition" in VSCode works with and without parens.
playground link