Types can't save you from all errors caused by ==
. Particularly since undefined
and null
are compatible with all types. e.g. the following is an incorrect if :
var foo:number = null;
if (foo == undefined) {
console.log('is undefined'); // actually null
}
For more info on why these are equal https://stackoverflow.com/a/359509/95190
Personally : I have had this rule disabled and never had any issues. I don't compare with true/false/null/undefined
, just if
them. And typescript prevents comparing strings
and numbers
so that is not an error I need to deal with.