close

no-non-null-asserted-nullish-coalescing

Configuration

rslint.config.ts
import { defineConfig, ts } from '@rslint/core';

export default defineConfig([
  ts.configs.recommended,
  {
    rules: {
      '@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'error',
    },
  },
]);

Rule Details

Disallow non-null assertions in the left operand of a nullish coalescing operator.

The ?? nullish coalescing operator is designed to provide a default value when dealing with null or undefined. Using a non-null assertion ! in the left operand is contradictory and likely a mistake.

Examples of incorrect code for this rule:

foo! ?? bar;
foo.bazz! ?? bar;
foo()! ?? bar;

Examples of correct code for this rule:

foo ?? bar;
foo ?? bar!;
foo.bazz ?? bar;

Original Documentation

https://typescript-eslint.io/rules/no-non-null-asserted-nullish-coalescing