close

no-confusing-non-null-assertion

Configuration

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

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

Rule Details

Disallow non-null assertion in locations that may be confusing.

A non-null assertion (!) placed immediately before =, ==, ===, in, or instanceof is visually almost indistinguishable from the operators !=, !==, !(... in ...), or !(... instanceof ...). This rule flags those combinations and offers suggestions to either remove the assertion or wrap the left-hand side in parentheses to disambiguate.

Examples of incorrect code for this rule:

a! == b;
a! === b;
a! in b;
a! instanceof b;

Examples of correct code for this rule:

a == b;
(1 + foo.num!) == 2;
foo.bar == 'hello';
!(a in b);

Original Documentation