Closed
Description
Currently if you write
type C<T> = T extends infer U ? U : U;
// ~ Cannot find name "U"
We give you an error because U
is not in scope at all in the false arm.
This is a) confusing (U
is right there!) and b) a landmine, because you might have an outer type of the same name
// Elsewhere
type U = string;
// ...
/// Not what I meant!
type C<T> = T extends infer U ? number : U;
We should keep U
in scope in both cases and disallow its use with an explicit error message, e.g. (please bikeshed):
Inferred type parameter "U" is unmatched in this case and cannot be used
This should not block nesting of lexical scopes; i.e. this should still be legal because each U
would shadow the outer expression's:
type C<T> = T extends Array<infer U> ? U :
T extends Promise<infer U> ? U :
never;