# @typescript-eslint/no-non-null-assertion

> Disallow the non-null assertion `value!`

`value!` tells TypeScript that `value` isn't `null` or `undefined`. Nothing checks that when the code runs. If you're wrong, or the code around it changes, `value!.name` throws a `TypeError`, which is the error strict null checks are meant to prevent.

Check the value, or use `?.` or `??`, which do their work at runtime.

{/* 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-non-null-assertion" = "error" # or "warn"
```

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

## Examples

Reported:

{/* bad {"count": 2} */}
```ts
const users = new Map<string, { name: string }>();

function greet(id: string) {
  const form = document.querySelector("form")!;
  form.title = users.get(id)!.name;
}
```

Not reported:

{/* good */}
```ts
const users = new Map<string, { name: string }>();

function greet(id: string) {
  const form = document.querySelector("form");
  if (!form) {
    throw new Error("The page has no form");
  }
  form.title = users.get(id)?.name ?? "guest";
}
```

## When not to use it

Sometimes you know more than the type checker, for example right after `map.has(key)`. If your code has many places like that and you trust them, this rule is noise.
