Please help me to understand how TS narrow types. I have a simple foo function which has forEach iterator over an arbitrary array. It's clear that console.log will log false after executing this code, but TS insists that it's true, which is wrong.
My expectation is if TS can't handle forEach or similar functions because of possible asynchronity, then it should suggest boolean. This situation really frustrates me and slows my productivity, because I need to re-check everything 10 times to prove that TS is wrong and my code is correct.
function foo() {
let canActivate = true;
['foo'].forEach(() => {
canActivate = false;
})
console.log(canActivate);
}
foo();
