persona-community-5/.pnpm-store/v3/files/90/2aa38a4416d0c1bc4a50c252b55832150b033e1b2371d862a407856683fdd26c8720c257c9396fa25e2f7a227ea44959e9e807c579f1344d4a1c4bf0c1f200
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

61 lines
1.1 KiB
Plaintext

---
description: 'Disallow extra non-null assertions.'
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
> 🛑 This file is source code, not the primary documentation location! 🛑
>
> See **https://typescript-eslint.io/rules/no-extra-non-null-assertion** for documentation.
The `!` non-null assertion operator in TypeScript is used to assert that a value's type does not include `null` or `undefined`.
Using the operator any more than once on a single value does nothing.
## Examples
<Tabs>
<TabItem value="❌ Incorrect">
```ts
const foo: { bar: number } | null = null;
const bar = foo!!!.bar;
```
```ts
function foo(bar: number | undefined) {
const bar: number = bar!!!;
}
```
```ts
function foo(bar?: { n: number }) {
return bar!?.n;
}
```
</TabItem>
<TabItem value="✅ Correct">
```ts
const foo: { bar: number } | null = null;
const bar = foo!.bar;
```
```ts
function foo(bar: number | undefined) {
const bar: number = bar!;
}
```
```ts
function foo(bar?: { n: number }) {
return bar?.n;
}
```
</TabItem>
</Tabs>
{/* Intentionally Omitted: When Not To Use It */}