-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Return type union with empty object is just empty object #54888
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
Comments
This is just normal subtype reduction. Everything (except |
Duplicate of #50171, #49710, and likely others. |
But it is a mistake to do the subtype reduction for infered return types, because it hides the actual returns. |
The inferred return type here is no different in concept to the inferred type of the ternary expression in #50171. It's inconvenient, but ultimately not considered a bug. |
|
closing since ts wont solve the problem... There should be a type saing its just an empty object or sth else and not a "base type" that just includes everything since its just wrong... |
See #12936. |
Bug Report
π Search Terms
conditional return
return type option missing
only first return type
empty object return
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
If a function returns either an empty object or a number (could also be or a promise or anything) the return type will be just empty object instead of a union type. It is wrong because a number or promise doesnt equal to an empty object. A promise is much more than an empty object and it should be typed that way, a number is just totally different in usage and should therefore be typed with a union.
π Expected behavior
The expected behaviour would be a return type as a union like "1 | {}" or "{} | Promise"
The text was updated successfully, but these errors were encountered: