question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Key Remapping in Mapped Types does not contribute to the reference of the original type

See original GitHub issue

Bug Report

Key Remapping in Mapped Types does not contribute to the reference of the original type

🔎 Search Terms

Key Remapping in Mapped Types does not contribute to the reference of the original type

🕗 Version & Regression Information

  • This changed between versions 4.1 and nightly 20210616

⏯ Playground Link

Playground link with relevant code

💻 Code

const x = {a: 1, b: 2}
x.a

declare const y: {
  [key in keyof typeof x]: boolean
}
y.a

declare const z: {
  [key in keyof typeof x as `get_${key}`]: boolean
}
z.get_a

🙁 Actual behavior

x.a has references on line 2 and line 7

🙂 Expected behavior

x.a has references on line 2, line 7, and line 12

Rename x.a to x.c should rename line 12 to get_c

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
RyanCavanaughcommented, Apr 20, 2022

This turns out to be way harder than just a bugfix. The find-all-references code depends on being able to quickly reduce the set of candidate positions to look for based on the identifier tokens in each source file, but we don’t have any way to know that get_a should be counted as a reference to a since this operation occurs syntactically before we have any type information.

2reactions
Jack-Workscommented, Jun 22, 2021

Note to self: Have GAB look at this in a couple weeks

Thanks, that’s very helpful!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Key remapping breaks definition navigation for mapped ...
When using mapped type with key remapping, definitions for the properties of mapped types are no longer discoverable. Though, references are ...
Read more >
Mapped Types with Key Remapping mixed in with other ...
So I am trying to do something like below with key remapping, passing in a second generic type optionally to spread out its...
Read more >
Mastering TypeScript mapped types
In this post, we'll cover mapped types in TypeScript, a real-world example of them, and utility types including Partial, Readonly, and Pick.
Read more >
Documentation - Mapped Types
Generating types by re-using an existing type.
Read more >
keyof and Mapped Types In TypeScript 2.1
Both of these are syntax that sits on top of normal JavaScript to add type analysis — basically, a form of gradual typing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found