No Implicit Boolean
Require explicit comparisons in conditions instead of relying on truthy/falsy coercion.
Summary
The no-implicit-boolean rule reports bare identifiers, member expressions, call expressions, await expressions, and their negations (!value, !fn(), !await fn()) when used as conditions in if, while, do...while, for, and ternary statements.
Negations (!value, !fn(), !await fn()) are also flagged when they appear outside conditions, such as in assignments or return statements (e.g. const x = !value;).
For logical expressions (&&, ||), each operand is checked independently.
Why Use This Rule?
- Prevents subtle bugs from truthy/falsy coercion (e.g.,
0,"", andnullare all falsy). - Makes the developer's intent explicit (
=== undefined,=== true,> 0). - Keeps conditions self-documenting so readers understand what is actually being checked.
Examples
Configuration
Options
warning
ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.
| Option | Type | Default | Description |
|---|---|---|---|
ignoreFiles | string[] | [] | File names to skip. Supports a leading-* suffix (*.test.ts), an exact path, or a trailing path segment; ** globs are not supported. |
Autofix
Autofix is not available for this rule. Flagged code must be updated manually.
Troubleshooting
- Warning fires on
!Array.isArray(x)— UseArray.isArray(x) === falseinstead. All negations of identifiers, member expressions, and call expressions are flagged. - Warning fires on
if (value && other)— Each operand in a logical expression is checked independently. Bothvalueandotherneed explicit comparisons. - Warning fires on a ternary condition — Ternary conditions are checked the same as
ifconditions. Use an explicit comparison like(isDryRun === true) ? a : b. - Warning fires on
!valueoutside an if/while — Negations of identifiers, member, call, and await expressions are checked anywhere they appear, not just in conditions.