microsoft / microsoft/TypeScript
Type parameter leak caused by `this` and reverse mapped type
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
### 🔎 Search Terms
type parameter leak reverse mapped type type variable this
### 🕗 Version & Regression Information
- This is the behavior in every version I tried
### ⏯ Playground Link
https://www.typescriptlang.org/play/?ts=6.0.0-dev.20251030#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwxAGcMAeAFXhAA9DVgj4AlcHGYUkmLVAcwBp4aANaocAd1QA+KQAocAIwBWALngBvAFDx4AbQDS8HvGEgAnjkTxyAXTWyAlPAC8U6wZsBuTQF8Ha8m9NMDwSeEUlFwJiDFktHQB6BJ14AD0Afm14KEcNLJ04DGQYfAAGbx0ffiyFXPiUwuL8DAALLCIAOhyHCvgq3x7NTSA
### 💻 Code
```ts
declare function test>(obj: {
[K in keyof T]: () => T[K];
}): T;
const obj = test({
// ^? const obj: { a: number; b: T[string]; }
a() {
return 0;
},
b() {
return this.a();
},
});
```
### 🙁 Actual behavior
`obj`'s type refers to `T[string]`
### 🙂 Expected behavior
`T` definitely shouldn't leak into `obj`'s type
### Additional information about the issue
_No response_
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 il problema usando il TypeScript Playground collegato e l’esempio di reverse-mapped type fornito. Traccia il modo in cui il checker inferisce il tipo restituito quando il metodo dell’oggetto usa `this`, quindi verifica che il tipo `obj` risultante non esponga più il parametro generico `T`.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100