Closed
Description
Consider this code:
function fact( x: number, acc?: number ) {
if (x <= 1) return acc;
else return fact( x - 1, (acc||1)*x );
}
var res = fact( 5 );
Here, fact
is inferred to have type (number, number?) => any
, and consequently res
is inferred to have type any
.
This is vaguely reminiscent of cases #1146, #475, and #523, but those deal with some esoteric circumstances, while this here is a textbook case of a tail-recursive algorithm. Should work.
Note: no, it doesn't have to do with optional parameter, I checked.