demo code as below
let bool: boolean = false;
[1, 2, 3, 4].forEach(i => {
// do something ...
if(i === 2){
bool = true;
}
})
if (bool === true) {
console.log('this is test code')
}
This demo code got this error.
This comparison appears to be unintentional because the types ‘false’ and ‘true’ have no overlap.
I can adjust code like this to remove error.
// same code ...
if (bool) {
console.log('this is test code')
}
but I wanna know the bool variable in if statement is true instead 1 or something else.
how can I do ?