What
The following code results in an error message which could be improved upon: -
let y =
if test > 10 then "test"
else 123
The error is: -
error FS0001: This expression was expected to have type string but here has type int
Why
Newcomers to expression-based conditionals often do not understand that all branches of a conditional must evaluate to the same type of result. The current error message identifies that two types do not match, but does not make clear the context in which this is an error.
How
A better error might be:
All branches of an if / else expression must return the same type. The other values in this if / else expression all return a value of type string.
If possible, the values of the other branches should be included in the error message (of course, this will not always be possible).