Here is a code snippet for calculating the sum:
//Function to calculate the sum of an array of numbers
let sum =
([head, ...tail]: number[]) => head ? head + sum(tail) : 0
let result: string = sum([1, 2, 3]);
alert(result);
Can anyone explain why TypeScript infers the return type of sum
as any
? Interestingly, Flow reports an error for this code snippet, which seems correct.