-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Salsa type inference should find or types #6663
Comments
In TypeScript this is an error of "unknown type". If the types are relatable, we return the type that is the super-type of all return expressions. We explicitly don't try and synthesize a type as this code pattern often indicates a bug. |
@billti, we should reconsider this one. the reason we stop this in TS, is we want ppl to go look at their code and make sure this is what they really intend. for JS, we do not have this error, so it seems unjustified to just block inference from the return types. |
We could easily make the checker say that the function returns |
I'm wary of adding complexity to the code base and diverging the TypeScript and JavaScript behavior too greatly. If it's simple enough that the benefit outweighs the cost, sounds good to me. I'd note though that for compatible types we already return the most common super type (which effectively gives you the same completions as a union type). For cases when the types are truly distinct (e.g. the number and string scenario above), is a union type going to be of much value? I suppose if folks are using type guards, or we add better narrowing going forward... |
Thank you! 👍 |
From @alexandrudima on January 27, 2016 10:49
Testing #2218
Hovering over a1() shows its return type is
number
. Hovering over a2() shows its return type isany
. IMHO it should shownumber|string
-- maybe this inference code was written before or types were introduced?Copied from original issue: microsoft/vscode#2431
The text was updated successfully, but these errors were encountered: