microsoft / microsoft/TypeScript

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

Open
#61,094 1 comment 1 reaction 0 assignees View on GitHub
Domain: LS: Signature Help Experience Enhancement Help Wanted Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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:
``` ts
interface Source {
alpha: number;
beta: string;
}

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

type Result = Transformed;
/*
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.

Contributor guide

Open the contributing guide

Research direction

Reproduce the mapped-type example with TypeScript 5.7.3 and test Go to Definition from `alphaSuffix` to `Source.alpha`. Start by tracing the TypeScript language-service definition lookup for mapped types and template literal keys; done means the transformed key navigates to its original interface field and the behavior has regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.