Skip to content

unnecessaryBooleanCasts

Reports unnecessary boolean casts.

✅ This rule is included in the ts logical presets.

Boolean contexts such as if and while statements evaluate values for falsiness or truthiness. Using !!value or Boolean(value) in those contexts is redundant because that doesn’t change whether the value is falsy or truthy.

This rule reports on boolean casts in already-boolean contexts.

if (!!value) {
// ...
}
while (Boolean(condition)) {
// ...
}

This rule is not configurable.

If you prefer explicit boolean casts for clarity, this rule may not be for you.

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