Imagine having a straightforward piece of logic like this:
let bool = false
const seven = 7
const arr = [1,2,3,4,5,6,7]
arr.forEach(element => {
if (element === seven) {
bool = true
}
});
Now the goal is to execute a function if "bool" is set to true:
if (bool === true){
doSomething()
}
However, Typescript raises an error in this scenario:
This condition will always return 'false' since the types 'false' and 'true' have no overlap.
Despite knowing that logically bool will be true when the condition block is triggered, Typescript still gives an error. How can this issue be resolved?