Skip to content

Commit 7be5657

Browse files
authored
docs(eslint-plugin): no-unnecessary-type-assertion: Add non-null operator example (typescript-eslint#253)
* docs(eslint-plugin): Add non-null operator example * format
1 parent 225fc26 commit 7be5657

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Diff for: packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md

+12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ type Foo = 3;
2727
const foo = 3 as Foo;
2828
```
2929

30+
```ts
31+
function foo(x: number): number {
32+
return x!; // unnecessary non-null
33+
}
34+
```
35+
3036
Examples of **correct** code for this rule:
3137

3238
```ts
@@ -37,6 +43,12 @@ const foo = <number>3;
3743
const foo = 3 as number;
3844
```
3945

46+
```ts
47+
function foo(x: number | undefined): number {
48+
return x!;
49+
}
50+
```
51+
4052
### Options
4153

4254
This rule optionally takes an object with a single property `typesToIgnore`, which can be set to a list of type names to ignore.

0 commit comments

Comments
 (0)