Skip to content

typescript/no-confusing-non-null-assertion Suspicious

🚧 An auto-fix is planned for this rule, but not implemented at this time.

What it does

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

Why is this bad?

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 (!= !==).

Examples

Examples of incorrect code for this rule:

ts
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(`===`)

Examples of correct code for this rule:

ts
a == b;
a !== b;
a === b;

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "typescript/no-confusing-non-null-assertion": "error"
  }
}
bash
oxlint --deny typescript/no-confusing-non-null-assertion

References

Released under the MIT License.