Closed
Description
Via #919
Even with union types, we still require that a best common type can be selected from the types of the return expressions in a function:
function fn() { // Error, return expressions do not have a BCT
if(x) {
return 'foo';
} else {
return 42;
}
}
If this is the desired behavior, the user must write
function fn(): number|string {
This is inconsistent with how we're treating other cases, e.g. var x = [1, 'foo'];
produces anArray<number|string>
.
Is the desired behavior here that we infer a more complex union type return type for a function, or that we enforce a consistent set of return expression types when no other information is given?