Closed
Description
🔎 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
💻 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.