TS7023

error TS7023: ‘fibonacci‘ implicitly has return type ‘any‘ because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

Broken Code ❌

1
2
3
function fibonacci(n) {
return n <= 1 ? n : fibonacci(n - 1) + fibonacci(n - 2);
}

Fixed Code ✔️

To avoid the implicit typing of any for the return type, you have to add a return type annotation:

1
2
3
function fibonacci(n): number {
return n <= 1 ? n : fibonacci(n - 1) + fibonacci(n - 2);
}