Skip to main content

Disallow non-null assertion in locations that may be confusing (no-confusing-non-null-assertion)

Rule Details

Using a non-null assertion (!) next to an assign or equals check (= or == or ===) creates code that is confusing as it looks similar to a not equals check (!= !==).

a! == b; // a non-null assertions(`!`) and an equals test(`==`)
a !== b; // not equals test(`!==`)
a! === b; // a non-null assertions(`!`) and an triple equals test(`===`)
interface Foo {
bar?: string;
num?: number;

const foo: Foo = getFoo();
const isEqualsBar =! == 'hello';
const isEqualsNum = 1 + foo.num! == 2;

When Not To Use It

If you don't care about this confusion, then you will not need this rule.

Further Reading


  • โœ… Recommended
  • ๐Ÿ”ง Fixable
  • ๐Ÿ’ญ Requires type information