-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Conditional return types don't work #46127
Comments
What I'm really trying to do: I'm trying to write a function that when giving a string returns The closest I got this to working is with overloads but then I couldn't get it working with downstream functions even if they had overloads. https://www.typescriptlang.org/play?ts=4.4.3#code/JYOwLgpgTgZghgYwgAgOpTgB0xAJgHgBUA+ZAbwChlkoI5cB7EAGwE9kxWcAuZAIgDuGbHj4BuKjTqMW7AG5xmAVwi9CEgL4VtMJSARhgTZAiZzoYABQAPXgGcwUUAHMAlMl7osOAg6chnYgldfUNjUxBzKDAiYhtPYR9Y9wTvPFjgvQMjEBMzC3jkPQBrEAYBEBSikFLy3MpqamAYS04cBhhka2QAXj7+Pxc+VwbGsdowJSh6ttV+ITTcPgAaZAVlOesNCTGtcYhJ6a6KLR0ssNycKABbYDs7YHMAMXOc2MLBgOQAHzRE9JKZQqxCqXhEBEBdVIowmU1yESiVmsrk02jRQA So I tried to be smart about doing the conditional in the return type and saw this bug. |
duplicate of #33912 |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
π Search Terms
conditional return type alias generics
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
Both branches have different flavors of error 2322
π Expected behavior
the typeof guard should have let Typescript know it was dealing with a string and should have now which branch of the conditional type it should be allowed to return. The same outside of the type guard since it returns and control flow analysis should have treated that like an implicit else.
The text was updated successfully, but these errors were encountered: