---
title: "@typescript-eslint/no-confusing-non-null-assertion"
description: "Disallow a non-null assertion `!` right before `=`, `==`, `===`, `in` or `instanceof`"
# Generated by src/codegen/lint-rule-docs.ts. Do not edit below this line.
plugin: "typescript"
aliases: ["typescript-eslint/no-confusing-non-null-assertion","typescript/no-confusing-non-null-assertion"]
kind: "problem"
category: "suspicious"
default: "off"
fixable: "suggestion"
typeAware: false
deprecated: false
---

`user! == other` asserts that `user` isn't null and then tests for equality. It reads like `user !== other`, which means the opposite. In the same way, `count! = 1` looks like `count != 1`, and `key! in cache` looks like `!(key in cache)`.

The report comes with a suggestion to remove the `!`, or to put the left side in parentheses.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-confusing-non-null-assertion" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 3} */}
```ts
declare let user: string | undefined;
declare const cache: Record<string, number>;

const isSame = user! == "ada";
user! = "grace";
const isCached = user! in cache;
```

Not reported:

{/* good */}
```ts
declare let user: string | undefined;
declare const cache: Record<string, number>;

const isSame = user == "ada";
user = "grace";
const isCached = (user!) in cache;
const isOther = "ada" == user!;
```
