Skip to content

Type parameter leak caused by this and reverse mapped typeΒ #62779

@Andarist

Description

@Andarist

πŸ”Ž 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

declare function test<T extends Record<string, unknown>>(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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions