Skip to content

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

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: This-TypingThe issue relates to providing types to thisHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions