mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-04 17:29:31 +08:00
64 lines
938 B
Text
64 lines
938 B
Text
---
|
|
description: 'Disallow extra non-null assertion.'
|
|
---
|
|
|
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
>
|
|
> See **https://typescript-eslint.io/rules/no-extra-non-null-assertion** for documentation.
|
|
|
|
## Rule Details
|
|
|
|
Examples of code for this rule:
|
|
|
|
<!--tabs-->
|
|
|
|
### ❌ 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;
|
|
}
|
|
```
|
|
|
|
### ✅ 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;
|
|
}
|
|
```
|
|
|
|
## Options
|
|
|
|
```jsonc
|
|
// .eslintrc.json
|
|
{
|
|
"rules": {
|
|
"@typescript-eslint/no-extra-non-null-assertion": "error"
|
|
}
|
|
}
|
|
```
|
|
|
|
This rule is not configurable.
|