I have an error in the code that I am trying to resolve. I think it needs a return
statement but I have that already outside of the forEach
loop but it still throws the error:
not all the code path return the value
How to fix below code?
main.ts
:
private ValidateRequestArgs(str) {
let ret: boolean = true;
// here on val its throwing tslint error not all code paths return value
str.split(',').forEach((val) => {
if (!ret) {
return false;
}
if (List.indexOf(val) > -1) {
ret = true;
} else {
ret = false;
}
});
return ret;
}
return
in your function, so it considers your function always has to return something, which is not the case. What if you add areturn true;
after theelse
statement? – W