Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeScript] Mapped Types with Template Literal Keys Do Not Preserve Type Declaration References #61094

Open
JooYang opened this issue Jan 31, 2025 · 1 comment · May be fixed by #61061
Open
Labels
Domain: Signature Help Information in editor tooltips when invoking a function call Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@JooYang
Copy link

JooYang commented Jan 31, 2025

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.96.4 (Universal)
  • OS Version: Darwin arm64 23.6.0 (macOS Sonoma 14.7.2)
  • TypeScript Version: 5.7.3

When using Mapped Types with template literal transformations on interface fields, VSCode does not retain the original type reference. This makes it impossible to use “Go to Definition” to navigate from the transformed key back to its original declaration. WebStorm correctly maintains this reference, but VSCode does not.

Steps to Reproduce:

interface Source {
  alpha: number;
  beta: string;
}

// Transforming interface field names with a suffix
type Transformed<T> = {
  [K in keyof T as `${K & string}Suffix`]: () => T[K];
};

type Result = Transformed<Source>;
/*
Expected:
{
  alphaSuffix: () => number;
  betaSuffix: () => string;
}
*/

const obj: Result = {
  alphaSuffix: () => 42,
  betaSuffix: () => "hello",
};

// ❌ In VSCode, "Go to Definition" on `alphaSuffix` does not navigate to `alpha` in `Source`
obj.alphaSuffix();

Expected Behavior

  • “Go to Definition” on alphaSuffix should navigate to alpha in Source.
  • VSCode should retain the reference between transformed keys and their original interface field names.
  • This works as expected in WebStorm, where alphaSuffix correctly links back to alpha.

Actual Behavior

  • VSCode treats transformed keys as completely new identifiers, losing the connection to their original interface fields.
  • “Go to Definition” does not work for mapped types with template literal keys.
  • WebStorm successfully tracks the transformation and allows navigation to alpha.
@mjbvz mjbvz transferred this issue from microsoft/vscode Jan 31, 2025
@mjbvz mjbvz removed their assignment Jan 31, 2025
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Help Wanted You can do this Domain: Signature Help Information in editor tooltips when invoking a function call Experience Enhancement Noncontroversial enhancements labels Jan 31, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jan 31, 2025
@Zzzen Zzzen linked a pull request Feb 1, 2025 that will close this issue
@Zzzen
Copy link
Contributor

Zzzen commented Feb 1, 2025

I’m curious about how WebStorm allows navigation to the original declarations. Doesn’t it use tsserver under the hood?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Signature Help Information in editor tooltips when invoking a function call Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants