# strict-boolean-expressions

Rule `typescript/strict-boolean-expressions`. Disallow certain types in boolean expressions

- Source: typescript
- Technologies: TypeScript
- Kind: suspicious
- Needs type information: yes
- Autofix: yes, in at least one linter
- Reach: 2.6M weekly downloads of presets that enable it
- Trend: +92.2% last quarter
- Rank: #1474 by reach, #284 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `@typescript-eslint/strict-boolean-expressions` | no | suggestion | package `@typescript-eslint/eslint-plugin` | [docs](https://typescript-eslint.io/rules/strict-boolean-expressions) |
| Oxlint | `typescript/strict-boolean-expressions` | no | no | plugin `typescript`, category pedantic | [docs](https://oxc.rs/docs/guide/usage/linter/rules/typescript/strict-boolean-expressions.html) |
| Biome | `nursery/useStrictBooleanExpressions` | no | no | group nursery, since 2.5.15 | [docs](https://biomejs.dev/linter/rules/use-strict-boolean-expressions/) |

## Code examples

### Incorrect: the rule reports this

```ts
// nullable numbers are considered unsafe by default
declare const num: number | undefined;
if (num) {
  console.log('num is defined');
}

// nullable strings are considered unsafe by default
declare const str: string | null;
if (!str) {
  console.log('str is empty');
}

// nullable booleans are considered unsafe by default
function foo(bool?: boolean) {
  if (bool) {
    bar();
  }
}

// `any`, unconstrained generics and unions of more than one primitive type are disallowed
const foo = <T>(arg: T) => (arg ? 1 : 0);

// always-truthy and always-falsy types are disallowed
let obj = {};
while (obj) {
  obj = getObj();
}

// assertion functions without an `is` are boolean contexts.
declare function assert(value: unknown): asserts value;
let maybeString = Math.random() > 0.5 ? '' : undefined;
assert(maybeString);
// …
```

### Correct: the rule accepts this

```tsx
// nullable values should be checked explicitly against null or undefined
let num: number | undefined = 0;
if (num != null) {
  console.log('num is defined');
}

let str: string | null = null;
if (str != null && !str) {
  console.log('str is empty');
}

function foo(bool?: boolean) {
  if (bool ?? false) {
    bar();
  }
}

// `any` types should be converted to boolean explicitly
const foo = (arg: any) => (Boolean(arg) ? 1 : 0);
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import tseslint from "typescript-eslint";

export default [
  {
    plugins: { "@typescript-eslint": tseslint.plugin },
    rules: {
      "@typescript-eslint/strict-boolean-expressions": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "typescript/strict-boolean-expressions": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "useStrictBooleanExpressions": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |
| [eslint-config-love](https://lintradar.dev/presets/love.md) | ESLint | `eslint-config-love` | 258 | 171.7K | +39.3% |

## Related rules

- [typescript/prefer-nullish-coalescing](https://lintradar.dev/rules/typescript/prefer-nullish-coalescing.md): Enforce using the nullish coalescing operator instead of logical assignments or chaining
- [typescript/prefer-includes](https://lintradar.dev/rules/typescript/prefer-includes.md): Enforce `includes` method over `indexOf` method
- [typescript/non-nullable-type-assertion-style](https://lintradar.dev/rules/typescript/non-nullable-type-assertion-style.md): Enforce non-null assertions over explicit type assertions
- [typescript/no-unnecessary-qualifier](https://lintradar.dev/rules/typescript/no-unnecessary-qualifier.md): Disallow unnecessary namespace qualifiers
- [typescript/promise-function-async](https://lintradar.dev/rules/typescript/promise-function-async.md): Require any function or method that returns a Promise to be marked async
- [typescript/strict-void-return](https://lintradar.dev/rules/typescript/strict-void-return.md): Disallow passing a value-returning function in a position accepting a void function

---

Web page: https://lintradar.dev/rules/typescript/strict-boolean-expressions. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
