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

References

Released under the MIT License.