Skip to content

equalityOperatorNegations

Reports negated expressions on the left side of equality checks.

✅ This rule is included in the ts preset.

Using a negated expression as the left operand of an equality check is almost always a mistake. The logical not operator (!) has higher precedence than equality operators, so !a === b is evaluated as (!a) === b, not !(a === b). This converts the left operand to a boolean before comparing, which is rarely the intended behavior.

if (!
const value: any
value
=== true) {
const doSomething: any
doSomething
();
}
if (!
const count: any
count
=== 0) {
Error ts(2367) ― This comparison appears to be unintentional because the types 'boolean' and 'number' have no overlap.
const handleEmpty: any
handleEmpty
();
}

This rule is not configurable.

If you intentionally compare a negated boolean value with an equality operator, you may want to disable this rule. However, such code would be clearer if rewritten to use the opposite equality operator without the negation.

Made with ❤️‍🔥 around the world by the Flint team and contributors.