microsoft / microsoft/TypeScript
Type parameter leak caused by `this` and reverse mapped type
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
### 🔎 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_
贡献指南
调研方向
使用链接的 TypeScript Playground 和提供的 reverse-mapped type 示例复现该问题。跟踪对象方法使用 `this` 时 checker 如何推断返回类型,然后验证得到的 `obj` 类型不再暴露泛型参数 `T`。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100