Generic type with type variable is narrowed for arguments in a function call, but not in conditionals inside the function body #52327
Labels
Working as Intended
The behavior described is the intended behavior; this is not a bug
Bug Report
🔎 Search Terms
generics narrowing
generic type narrowing
dependent type narrowing
type narrowing control flow
type narrowing conditional
#50652 is probably related, but this current report 1) operates with generics and 2) shows that that the narrowing of function call arguments actually works opposed the the conditional inside the function body, which imho permits this being a new issue.
🕗 Version & Regression Information
This is the behavior in every version, including the current nightly, and I reviewed the FAQ for entries about Generics, Type Guards, etc.
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The type of a parameter is not narrowed in a conditional inside the function body based on a type variable and a generic type which depends on the type variable. However, where the function is actually called, its arguments are narrowed correctly based on the type variable and the generic type.
🙂 Expected behavior
I'd expect TypeScript to narrow the type in the conditional inside the function body based on the type variable and the generic type connected to it, as it can do the narrowing with the arguments when the function is called.
The text was updated successfully, but these errors were encountered: