microsoft / microsoft/TypeScript

Type parameter leak caused by `this` and reverse mapped type

Open
#62,779 1 comment 0 reactions 0 assignees View on GitHub
Bug Domain: This-Typing Help Wanted
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

### 🔎 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_

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue using the linked TypeScript Playground and the provided reverse-mapped type example. Trace how the checker infers the return type when the object method uses `this`, then verify that the resulting `obj` type no longer exposes the generic `T` parameter.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.