How to fix the issue not all the code paths return value?

The complaint is that the first if(){} is missing an else{} block with a return statement. You can disable this behaviour in a tsconfig file setting:

 "noImplicitReturns": false,

Of course you could also add

else {return ...}

But I would not recommend that, since forEach is not supposed to return anything as stated for example here:
What does `return` keyword mean inside `forEach` function?
or here:
https://codeburst.io/javascript-map-vs-foreach-f38111822c0f

Instead better get rid of the first if() altogether. Cheers

Leave a Comment