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.
Examples
Section titled “Examples”if (!!value) { // ...}while (Boolean(condition)) { // ...}if (value) { // ...}while (condition) { // ...}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you prefer explicit boolean casts for clarity, this rule may not be for you.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noExtraBooleanCast - Deno:
no-extra-boolean-cast - ESLint:
no-extra-boolean-cast - Oxlint:
eslint/no-extra-boolean-cast
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.