How to fix the issue not all the code paths return value?
You can resolve this error by two ways.
By editing the
noImplicitReturns
attribute to false intsconfig.json
"noImplicitReturns": false
- By adding a return statement for every path in your method. If you have 10 if conditions, then you have to add 10 return statements. It seems odd, but typescript recommends return for every path.
Here we can avoid the number of paths by the use of lambda expression.
private ValidateRequestArgs(str) {
return str.split(",").every(el => List.includes(el));
}
tsconfig.json
compilerOptions:{
"noImplicitReturns": false
}
The comlaint 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