Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbound type parameter leak when calling union of methods in some circumstances #57356

Closed
jcalz opened this issue Feb 9, 2024 · 0 comments · Fixed by #57371
Closed

Unbound type parameter leak when calling union of methods in some circumstances #57356

jcalz opened this issue Feb 9, 2024 · 0 comments · Fixed by #57371
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@jcalz
Copy link
Contributor

jcalz commented Feb 9, 2024

🔎 Search Terms

generic type parameter, union of functions, leak unbound escaped rogue fugitive

🕗 Version & Regression Information

  • This is the behavior in every version I tried (back to 4.2 anyway), and I reviewed the FAQ for entries about leaky generic

⏯ Playground Link

Furnished

💻 Code

interface Err<T> {
    f<U>(a: (err: T) => U): Err<U>;
}
interface Ok<T> {
    f(a: (err: T) => unknown): Err<T>;
}
declare const e: Err<0> | Err<1> | Ok<2>;
const e2 = e.f(e => e);
//    ^? const e2: Err<U> | Err<2> | Err<0 | 1 | 2>
//      what is U? --> ^

🙁 Actual behavior

The type of e2 is a union that includes Err<U>, where U is an unbound type parameter.

🙂 Expected behavior

I expect type parameters to stay in their scopes. As for what Err<U> should actually be... I think, uh, maybe it should be another copy of Err<0 | 1 | 2> or just omitted from the union?

Additional information about the issue

This is a minimal example derived from a Stack Overflow question.

Not sure if #43961 and #55467 are related, or if those are different manifestations of type parameter escape.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants