microsoft / microsoft/TypeScript
[TypeScript] Mapped Types with Template Literal Keys Do Not Preserve Type Declaration References
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci l’esempio di mapped types con TypeScript 5.7.3 e testa Go to Definition da `alphaSuffix` a `Source.alpha`. Inizia tracciando la ricerca delle definizioni del servizio linguistico di TypeScript per i mapped types e le chiavi di template literals; il lavoro è completato quando la chiave trasformata naviga fino al campo della sua interfaccia originale e il comportamento ha una copertura di regressione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- developer-experience
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100