Take a look at following code:
export class Smth {
private flag: boolean;
public update() {
this.flag = true;
this.inner();
if (this.flag === false) { // Operator '===' cannot be applied to types 'true' and 'false'.
console.log(123);
}
}
private inner() {
this.flag = false;
}
}
I can't understand what's wrong with the line
if (this.flag === false)
Typescript says
Operator '===' cannot be applied to types 'true' and 'false'.
But actually there are boolean
and false
.
I'm using typescript 2.6.2 but online playground shows the same result with 2.7.
It's not a dublicate of Operator '==' cannot be applied to types x and y in Typescript 2 as that question is about comparing constants. But in my code it's a chagable class field and there is a function that changes the value. Moreover, it is called.
this.flag = true;
this.inner(); // exectues this.flag = false;
if (this.flag === false) { // ... types 'true' and 'false'. - WHY?