microsoft / microsoft/TypeScript

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

Offen
#61,094 1 Kommentar 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Domain: LS: Signature Help Experience Enhancement Help Wanted Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere das Beispiel für mapped types mit TypeScript 5.7.3 und teste Go to Definition von alphaSuffix zu Source.alpha. Beginne damit, die Definitionssuche des TypeScript-Sprachdienstes für mapped types und Template-Literal-Schlüssel nachzuverfolgen; abgeschlossen ist die Aufgabe, wenn der transformierte Schlüssel zum Feld seiner ursprünglichen Schnittstelle navigiert und das Verhalten durch Regressionstests abgedeckt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
developer-experience
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.