Skip to content

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

🚧 An auto-fix is still under development.

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

Example

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

How to use

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

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

References

Released under the MIT License.