Key remapping breaks definition navigation for mapped type properties
See original GitHub issueBug Report
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
⏯ Playground Link
Playground link with relevant code
💻 Code
const object = {
a: 1, // ✅ can go to definition/references, can rename
b: 2, // ✅ can go to definition/references, can rename
c: 'ok', // ✅ no references, can rename
};
/** ✅ rename of {@link object.a} and {@link object.b} will correctly rename all the references as well */
const remapByKey: {
[P in keyof typeof object as P extends 'c' ? never : P]: 0;
} = { a: 0, b: 0 };
remapByKey.a; // ❌ can't go to definition, can't rename, ✅ yet highlights definition
remapByKey.b; // ❌ can't go to definition, can't rename, ✅ yet highlights definition
remapByKey.c; // ✅ errors as expected
const remapByValue: {
[P in keyof typeof object as typeof object[P] extends string ? never : P]: 0;
} = { a: 0, b: 0 };
remapByValue.a; // ❌ can't go to definition, can't rename, ✅ yet highlights definition
remapByValue.b; // ❌ can't go to definition, can't rename, ✅ yet highlights definition
remapByValue.c; // ✅ errors as expected
🙁 Actual behavior
🙂 Expected behavior
Capability to navigate to definition of remapped property.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Documentation - Mapped Types - TypeScript
Key Remapping via as. In TypeScript 4.1 and onwards, you can re-map keys in mapped types with an as clause in a mapped...
Read more >Typescript remap array to object with intellisense on keys
First the input object. If you use an explicit type, all information about specific values of the object you assign to it is...
Read more >8 Creating and Using Mappings
A mapping is made up of and defined by the following parts: ... or enter the new attribute's name, data type, and other...
Read more >What's New in EF Core 7.0 - Microsoft Learn
Mapping to JSON columns. In EF Core, aggregate types are defined using OwnsOne and OwnsMany . For example, consider the aggregate type from...
Read more >Mapper XML Files - MyBatis.org
Both id and result map a single column value to a single property or field of a simple data type (String, int, double,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It definitely “should” work, but it’s a bit tricky to implement AFAIR
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