---
title: "@typescript-eslint/non-nullable-type-assertion-style"
description: "Require `value!` instead of `value as T` when the assertion only removes `null` and `undefined`"
# Generated by src/codegen/lint-rule-docs.ts. Do not edit below this line.
plugin: "typescript"
aliases: ["typescript-eslint/non-nullable-type-assertion-style","typescript/non-nullable-type-assertion-style"]
kind: "suggestion"
category: "restriction"
default: "off"
fixable: "yes"
typeAware: true
deprecated: false
---

If `name` is a `string | undefined`, then `name as string` and `name!` do the same thing. The `!` is shorter, and it says exactly what you're claiming, which is that the value is there. It also doesn't repeat the type, so there's nothing to update when the type changes.

`--fix` rewrites the assertion to `!`.

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

## Configure

Off by default. This rule needs types, so turning it on makes `bun lint` type check your code first.

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/non-nullable-type-assertion-style" = "error" # or "warn"
```

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

## Examples

Reported:

{/* bad */}
```ts
function nameOf(names: Map<string, string>, id: string) {
  return names.get(id) as string;
}
```

Not reported:

{/* good */}
```ts
function nameOf(names: Map<string, string>, id: string) {
  return names.get(id)!;
}
```

An assertion that does more than remove `null` and `undefined` can't be written with `!`, so it's allowed:

{/* good */}
```ts
function toText(value: string | number | null) {
  return value as string;
}
```

## When not to use it

`@typescript-eslint/no-non-null-assertion` reports every `!`. Don't turn on both.
