Skip to content

strictBooleanExpressions

Reports non-boolean types in boolean contexts that may cause unexpected behavior.

✅ This rule is included in the ts logical presets.

JavaScript allows any value in boolean contexts like if statements, ternary expressions, and logical negation. While primitives like strings and numbers have well-understood coercion rules, certain types in boolean contexts can indicate bugs or unclear code.

This rule reports:

  • Using any in a boolean context, which defeats type safety
  • Nullable booleans (boolean | null or boolean | undefined), where null/undefined silently coerce to false
  • Non-nullable objects that are always truthy, making the condition redundant
declare const value: any;
if (value) {
}
declare const flag: boolean | null;
if (flag) {
}
const config = { enabled: true };
if (config) {
}

This rule is not configurable.

If your codebase intentionally relies on truthy/falsy coercion for nullable booleans or uses any types extensively, you may want to disable this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.