@typescript-eslint/eslint-plugin 7.2.1-alpha.1 → 7.2.1-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/configs/all.js +1 -0
- package/dist/configs/all.js.map +1 -1
- package/dist/configs/disable-type-checked.js +1 -0
- package/dist/configs/disable-type-checked.js.map +1 -1
- package/dist/configs/strict-type-checked-only.js +23 -3
- package/dist/configs/strict-type-checked-only.js.map +1 -1
- package/dist/configs/strict-type-checked.js +27 -4
- package/dist/configs/strict-type-checked.js.map +1 -1
- package/dist/configs/strict.js +4 -1
- package/dist/configs/strict.js.map +1 -1
- package/dist/rules/ban-ts-comment.js +4 -1
- package/dist/rules/ban-ts-comment.js.map +1 -1
- package/dist/rules/consistent-type-imports.js +1 -0
- package/dist/rules/consistent-type-imports.js.map +1 -1
- package/dist/rules/index.js +2 -0
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/no-floating-promises.js +4 -1
- package/dist/rules/no-floating-promises.js.map +1 -1
- package/dist/rules/no-misused-promises.js +1 -1
- package/dist/rules/no-misused-promises.js.map +1 -1
- package/dist/rules/no-redundant-type-constituents.js +42 -0
- package/dist/rules/no-redundant-type-constituents.js.map +1 -1
- package/dist/rules/no-unnecessary-qualifier.js +1 -1
- package/dist/rules/no-unnecessary-qualifier.js.map +1 -1
- package/dist/rules/no-unsafe-argument.js +1 -25
- package/dist/rules/no-unsafe-argument.js.map +1 -1
- package/dist/rules/no-unused-expressions.js +6 -2
- package/dist/rules/no-unused-expressions.js.map +1 -1
- package/dist/rules/restrict-plus-operands.js +12 -1
- package/dist/rules/restrict-plus-operands.js.map +1 -1
- package/dist/rules/restrict-template-expressions.js +52 -87
- package/dist/rules/restrict-template-expressions.js.map +1 -1
- package/dist/rules/use-unknown-in-catch-callback-variable.js +283 -0
- package/dist/rules/use-unknown-in-catch-callback-variable.js.map +1 -0
- package/dist/util/misc.js +10 -1
- package/dist/util/misc.js.map +1 -1
- package/docs/rules/TEMPLATE.md +10 -4
- package/docs/rules/{adjacent-overload-signatures.md → adjacent-overload-signatures.mdx} +11 -5
- package/docs/rules/{array-type.md → array-type.mdx} +24 -12
- package/docs/rules/{await-thenable.md → await-thenable.mdx} +10 -4
- package/docs/rules/{ban-ts-comment.md → ban-ts-comment.mdx} +32 -18
- package/docs/rules/{ban-tslint-comment.md → ban-tslint-comment.mdx} +10 -4
- package/docs/rules/{ban-types.md → ban-types.mdx} +11 -5
- package/docs/rules/{block-spacing.md → block-spacing.mdx} +3 -0
- package/docs/rules/{brace-style.md → brace-style.mdx} +3 -0
- package/docs/rules/camelcase.md +3 -5
- package/docs/rules/{class-literal-property-style.md → class-literal-property-style.mdx} +18 -11
- package/docs/rules/{class-methods-use-this.md → class-methods-use-this.mdx} +12 -6
- package/docs/rules/{comma-dangle.md → comma-dangle.mdx} +3 -0
- package/docs/rules/{comma-spacing.md → comma-spacing.mdx} +3 -0
- package/docs/rules/{consistent-generic-constructors.md → consistent-generic-constructors.mdx} +17 -8
- package/docs/rules/{consistent-indexed-object-style.md → consistent-indexed-object-style.mdx} +17 -8
- package/docs/rules/{consistent-return.md → consistent-return.mdx} +10 -4
- package/docs/rules/{consistent-type-assertions.md → consistent-type-assertions.mdx} +15 -10
- package/docs/rules/{consistent-type-definitions.md → consistent-type-definitions.mdx} +17 -8
- package/docs/rules/{consistent-type-exports.md → consistent-type-exports.mdx} +17 -8
- package/docs/rules/{consistent-type-imports.md → consistent-type-imports.mdx} +13 -8
- package/docs/rules/{default-param-last.md → default-param-last.mdx} +10 -4
- package/docs/rules/{dot-notation.md → dot-notation.mdx} +3 -0
- package/docs/rules/{explicit-function-return-type.md → explicit-function-return-type.mdx} +59 -32
- package/docs/rules/{explicit-member-accessibility.md → explicit-member-accessibility.mdx} +3 -0
- package/docs/rules/{explicit-module-boundary-types.md → explicit-module-boundary-types.mdx} +39 -21
- package/docs/rules/{func-call-spacing.md → func-call-spacing.mdx} +3 -0
- package/docs/rules/{indent.md → indent.mdx} +3 -0
- package/docs/rules/{init-declarations.md → init-declarations.mdx} +3 -0
- package/docs/rules/{key-spacing.md → key-spacing.mdx} +3 -0
- package/docs/rules/{keyword-spacing.md → keyword-spacing.mdx} +3 -0
- package/docs/rules/{lines-around-comment.md → lines-around-comment.mdx} +3 -0
- package/docs/rules/{lines-between-class-members.md → lines-between-class-members.mdx} +3 -0
- package/docs/rules/{max-params.md → max-params.mdx} +3 -0
- package/docs/rules/{member-delimiter-style.md → member-delimiter-style.mdx} +13 -7
- package/docs/rules/{member-ordering.md → member-ordering.mdx} +92 -56
- package/docs/rules/{method-signature-style.md → method-signature-style.mdx} +17 -8
- package/docs/rules/{naming-convention.md → naming-convention.mdx} +3 -0
- package/docs/rules/{no-array-constructor.md → no-array-constructor.mdx} +10 -4
- package/docs/rules/{no-array-delete.md → no-array-delete.mdx} +9 -5
- package/docs/rules/{no-base-to-string.md → no-base-to-string.mdx} +12 -6
- package/docs/rules/{no-confusing-non-null-assertion.md → no-confusing-non-null-assertion.mdx} +11 -5
- package/docs/rules/{no-confusing-void-expression.md → no-confusing-void-expression.mdx} +10 -4
- package/docs/rules/{no-dupe-class-members.md → no-dupe-class-members.mdx} +4 -1
- package/docs/rules/{no-duplicate-enum-values.md → no-duplicate-enum-values.mdx} +10 -4
- package/docs/rules/{no-duplicate-imports.md → no-duplicate-imports.mdx} +1 -1
- package/docs/rules/{no-duplicate-type-constituents.md → no-duplicate-type-constituents.mdx} +10 -4
- package/docs/rules/{no-dynamic-delete.md → no-dynamic-delete.mdx} +10 -4
- package/docs/rules/{no-empty-function.md → no-empty-function.mdx} +3 -0
- package/docs/rules/{no-empty-interface.md → no-empty-interface.mdx} +9 -5
- package/docs/rules/{no-explicit-any.md → no-explicit-any.mdx} +15 -9
- package/docs/rules/{no-extra-non-null-assertion.md → no-extra-non-null-assertion.mdx} +11 -5
- package/docs/rules/{no-extra-parens.md → no-extra-parens.mdx} +3 -0
- package/docs/rules/{no-extra-semi.md → no-extra-semi.mdx} +3 -0
- package/docs/rules/{no-extraneous-class.md → no-extraneous-class.mdx} +61 -33
- package/docs/rules/{no-floating-promises.md → no-floating-promises.mdx} +12 -6
- package/docs/rules/{no-for-in-array.md → no-for-in-array.mdx} +10 -4
- package/docs/rules/{no-implied-eval.md → no-implied-eval.mdx} +10 -4
- package/docs/rules/{no-import-type-side-effects.md → no-import-type-side-effects.mdx} +12 -6
- package/docs/rules/{no-inferrable-types.md → no-inferrable-types.mdx} +9 -5
- package/docs/rules/{no-invalid-this.md → no-invalid-this.mdx} +4 -1
- package/docs/rules/{no-invalid-void-type.md → no-invalid-void-type.mdx} +10 -4
- package/docs/rules/{no-loop-func.md → no-loop-func.mdx} +3 -0
- package/docs/rules/{no-loss-of-precision.md → no-loss-of-precision.mdx} +3 -0
- package/docs/rules/{no-magic-numbers.md → no-magic-numbers.mdx} +3 -0
- package/docs/rules/{no-meaningless-void-operator.md → no-meaningless-void-operator.mdx} +12 -4
- package/docs/rules/{no-misused-new.md → no-misused-new.mdx} +10 -4
- package/docs/rules/{no-misused-promises.md → no-misused-promises.mdx} +24 -16
- package/docs/rules/{no-mixed-enums.md → no-mixed-enums.mdx} +14 -6
- package/docs/rules/{no-namespace.md → no-namespace.mdx} +29 -18
- package/docs/rules/{no-non-null-asserted-nullish-coalescing.md → no-non-null-asserted-nullish-coalescing.mdx} +10 -4
- package/docs/rules/{no-non-null-asserted-optional-chain.md → no-non-null-asserted-optional-chain.mdx} +10 -4
- package/docs/rules/{no-non-null-assertion.md → no-non-null-assertion.mdx} +10 -4
- package/docs/rules/{no-redeclare.md → no-redeclare.mdx} +4 -1
- package/docs/rules/{no-redundant-type-constituents.md → no-redundant-type-constituents.mdx} +10 -4
- package/docs/rules/{no-require-imports.md → no-require-imports.mdx} +18 -9
- package/docs/rules/{no-restricted-imports.md → no-restricted-imports.mdx} +10 -4
- package/docs/rules/{no-shadow.md → no-shadow.mdx} +4 -1
- package/docs/rules/{no-this-alias.md → no-this-alias.mdx} +24 -12
- package/docs/rules/{no-throw-literal.md → no-throw-literal.mdx} +11 -5
- package/docs/rules/{no-type-alias.md → no-type-alias.mdx} +5 -2
- package/docs/rules/{no-unnecessary-boolean-literal-compare.md → no-unnecessary-boolean-literal-compare.mdx} +24 -12
- package/docs/rules/{no-unnecessary-condition.md → no-unnecessary-condition.mdx} +11 -5
- package/docs/rules/{no-unnecessary-qualifier.md → no-unnecessary-qualifier.mdx} +10 -4
- package/docs/rules/{no-unnecessary-type-arguments.md → no-unnecessary-type-arguments.mdx} +10 -4
- package/docs/rules/{no-unnecessary-type-assertion.md → no-unnecessary-type-assertion.mdx} +10 -4
- package/docs/rules/{no-unnecessary-type-constraint.md → no-unnecessary-type-constraint.mdx} +10 -4
- package/docs/rules/{no-unsafe-argument.md → no-unsafe-argument.mdx} +14 -10
- package/docs/rules/{no-unsafe-assignment.md → no-unsafe-assignment.mdx} +14 -10
- package/docs/rules/{no-unsafe-call.md → no-unsafe-call.mdx} +15 -9
- package/docs/rules/{no-unsafe-declaration-merging.md → no-unsafe-declaration-merging.mdx} +10 -4
- package/docs/rules/{no-unsafe-enum-comparison.md → no-unsafe-enum-comparison.mdx} +9 -5
- package/docs/rules/{no-unsafe-member-access.md → no-unsafe-member-access.mdx} +15 -9
- package/docs/rules/{no-unsafe-return.md → no-unsafe-return.mdx} +14 -10
- package/docs/rules/{no-unsafe-unary-minus.md → no-unsafe-unary-minus.mdx} +11 -5
- package/docs/rules/{no-unused-expressions.md → no-unused-expressions.mdx} +3 -0
- package/docs/rules/{no-unused-vars.md → no-unused-vars.mdx} +3 -0
- package/docs/rules/{no-use-before-define.md → no-use-before-define.mdx} +10 -4
- package/docs/rules/{no-useless-constructor.md → no-useless-constructor.mdx} +3 -0
- package/docs/rules/{no-useless-empty-export.md → no-useless-empty-export.mdx} +10 -4
- package/docs/rules/{no-useless-template-literals.md → no-useless-template-literals.mdx} +10 -6
- package/docs/rules/{no-var-requires.md → no-var-requires.mdx} +18 -9
- package/docs/rules/{non-nullable-type-assertion-style.md → non-nullable-type-assertion-style.mdx} +10 -4
- package/docs/rules/{object-curly-spacing.md → object-curly-spacing.mdx} +3 -0
- package/docs/rules/{padding-line-between-statements.md → padding-line-between-statements.mdx} +3 -0
- package/docs/rules/{parameter-properties.md → parameter-properties.mdx} +66 -36
- package/docs/rules/{prefer-as-const.md → prefer-as-const.mdx} +9 -5
- package/docs/rules/{prefer-destructuring.md → prefer-destructuring.mdx} +23 -12
- package/docs/rules/{prefer-enum-initializers.md → prefer-enum-initializers.mdx} +10 -4
- package/docs/rules/{prefer-find.md → prefer-find.mdx} +10 -4
- package/docs/rules/{prefer-for-of.md → prefer-for-of.mdx} +11 -5
- package/docs/rules/{prefer-function-type.md → prefer-function-type.mdx} +10 -4
- package/docs/rules/{prefer-includes.md → prefer-includes.mdx} +11 -5
- package/docs/rules/{prefer-literal-enum-member.md → prefer-literal-enum-member.mdx} +16 -9
- package/docs/rules/{prefer-namespace-keyword.md → prefer-namespace-keyword.mdx} +9 -5
- package/docs/rules/{prefer-nullish-coalescing.md → prefer-nullish-coalescing.mdx} +3 -0
- package/docs/rules/{prefer-optional-chain.md → prefer-optional-chain.mdx} +58 -33
- package/docs/rules/{prefer-promise-reject-errors.md → prefer-promise-reject-errors.mdx} +10 -4
- package/docs/rules/{prefer-readonly-parameter-types.md → prefer-readonly-parameter-types.mdx} +36 -22
- package/docs/rules/{prefer-readonly.md → prefer-readonly.mdx} +17 -8
- package/docs/rules/{prefer-reduce-type-parameter.md → prefer-reduce-type-parameter.mdx} +10 -4
- package/docs/rules/{prefer-regexp-exec.md → prefer-regexp-exec.mdx} +10 -4
- package/docs/rules/{prefer-return-this-type.md → prefer-return-this-type.mdx} +10 -4
- package/docs/rules/{prefer-string-starts-ends-with.md → prefer-string-starts-ends-with.mdx} +9 -5
- package/docs/rules/{prefer-ts-expect-error.md → prefer-ts-expect-error.mdx} +10 -4
- package/docs/rules/{promise-function-async.md → promise-function-async.mdx} +24 -12
- package/docs/rules/{quotes.md → quotes.mdx} +3 -0
- package/docs/rules/{require-array-sort-compare.md → require-array-sort-compare.mdx} +17 -8
- package/docs/rules/{require-await.md → require-await.mdx} +3 -0
- package/docs/rules/{restrict-plus-operands.md → restrict-plus-operands.mdx} +54 -30
- package/docs/rules/{restrict-template-expressions.md → restrict-template-expressions.mdx} +24 -9
- package/docs/rules/{return-await.md → return-await.mdx} +24 -12
- package/docs/rules/{semi.md → semi.mdx} +4 -1
- package/docs/rules/{sort-type-constituents.md → sort-type-constituents.mdx} +31 -16
- package/docs/rules/{space-before-blocks.md → space-before-blocks.mdx} +10 -4
- package/docs/rules/{space-before-function-paren.md → space-before-function-paren.mdx} +3 -0
- package/docs/rules/{space-infix-ops.md → space-infix-ops.mdx} +3 -0
- package/docs/rules/{strict-boolean-expressions.md → strict-boolean-expressions.mdx} +11 -5
- package/docs/rules/{switch-exhaustiveness-check.md → switch-exhaustiveness-check.mdx} +19 -14
- package/docs/rules/{triple-slash-reference.md → triple-slash-reference.mdx} +30 -17
- package/docs/rules/{type-annotation-spacing.md → type-annotation-spacing.mdx} +49 -31
- package/docs/rules/{typedef.md → typedef.mdx} +60 -33
- package/docs/rules/{unbound-method.md → unbound-method.mdx} +12 -6
- package/docs/rules/{unified-signatures.md → unified-signatures.mdx} +18 -9
- package/docs/rules/use-unknown-in-catch-callback-variable.mdx +84 -0
- package/package.json +8 -8
- /package/docs/rules/{no-parameter-properties.md → no-parameter-properties.mdx} +0 -0
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow aliasing `this`.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-this-alias** for documentation.
|
|
@@ -11,9 +14,8 @@ or not managing scope well.
|
|
|
11
14
|
|
|
12
15
|
## Examples
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
### ❌ Incorrect
|
|
17
|
+
<Tabs>
|
|
18
|
+
<TabItem value="❌ Incorrect">
|
|
17
19
|
|
|
18
20
|
```ts
|
|
19
21
|
const self = this;
|
|
@@ -23,7 +25,8 @@ setTimeout(function () {
|
|
|
23
25
|
});
|
|
24
26
|
```
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
</TabItem>
|
|
29
|
+
<TabItem value="✅ Correct">
|
|
27
30
|
|
|
28
31
|
```ts
|
|
29
32
|
setTimeout(() => {
|
|
@@ -31,6 +34,9 @@ setTimeout(() => {
|
|
|
31
34
|
});
|
|
32
35
|
```
|
|
33
36
|
|
|
37
|
+
</TabItem>
|
|
38
|
+
</Tabs>
|
|
39
|
+
|
|
34
40
|
## Options
|
|
35
41
|
|
|
36
42
|
### `allowDestructuring`
|
|
@@ -41,9 +47,8 @@ You can explicitly disallow them by setting `allowDestructuring` to `false`.
|
|
|
41
47
|
|
|
42
48
|
Examples of code for the `{ "allowDestructuring": false }` option:
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
#### ❌ Incorrect
|
|
50
|
+
<Tabs>
|
|
51
|
+
<TabItem value="❌ Incorrect">
|
|
47
52
|
|
|
48
53
|
```ts option='{ "allowDestructuring": false }'
|
|
49
54
|
class ComponentLike {
|
|
@@ -59,7 +64,8 @@ class ComponentLike {
|
|
|
59
64
|
}
|
|
60
65
|
```
|
|
61
66
|
|
|
62
|
-
|
|
67
|
+
</TabItem>
|
|
68
|
+
<TabItem value="✅ Correct">
|
|
63
69
|
|
|
64
70
|
```ts option='{ "allowDestructuring": false }'
|
|
65
71
|
class ComponentLike {
|
|
@@ -73,6 +79,9 @@ class ComponentLike {
|
|
|
73
79
|
}
|
|
74
80
|
```
|
|
75
81
|
|
|
82
|
+
</TabItem>
|
|
83
|
+
</Tabs>
|
|
84
|
+
|
|
76
85
|
### `allowedNames`
|
|
77
86
|
|
|
78
87
|
`no-this-alias` can alternately be used to allow only a specific list of names as `this` aliases.
|
|
@@ -80,9 +89,8 @@ We recommend against this except as a transitory step towards fixing all rule vi
|
|
|
80
89
|
|
|
81
90
|
Examples of code for the `{ "allowedNames": ["self"] }` option:
|
|
82
91
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
#### ❌ Incorrect
|
|
92
|
+
<Tabs>
|
|
93
|
+
<TabItem value="❌ Incorrect">
|
|
86
94
|
|
|
87
95
|
```ts option='{ "allowedNames": ["self"] }'
|
|
88
96
|
class Example {
|
|
@@ -92,7 +100,8 @@ class Example {
|
|
|
92
100
|
}
|
|
93
101
|
```
|
|
94
102
|
|
|
95
|
-
|
|
103
|
+
</TabItem>
|
|
104
|
+
<TabItem value="✅ Correct">
|
|
96
105
|
|
|
97
106
|
```ts option='{ "allowedNames": ["self"] }'
|
|
98
107
|
class Example {
|
|
@@ -102,6 +111,9 @@ class Example {
|
|
|
102
111
|
}
|
|
103
112
|
```
|
|
104
113
|
|
|
114
|
+
</TabItem>
|
|
115
|
+
</Tabs>
|
|
116
|
+
|
|
105
117
|
## When Not To Use It
|
|
106
118
|
|
|
107
119
|
If your project is structured in a way that it needs to assign `this` to variables, this rule is likely not for you.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow throwing literals as exceptions.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-throw-literal** for documentation.
|
|
@@ -15,9 +18,8 @@ This rule restricts what can be thrown as an exception. When it was first create
|
|
|
15
18
|
|
|
16
19
|
This rule is aimed at maintaining consistency when throwing exception by disallowing to throw literals and other expressions which cannot possibly be an `Error` object.
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
### ❌ Incorrect
|
|
21
|
+
<Tabs>
|
|
22
|
+
<TabItem value="❌ Incorrect">
|
|
21
23
|
|
|
22
24
|
```ts
|
|
23
25
|
throw 'error';
|
|
@@ -48,7 +50,8 @@ const foo = {
|
|
|
48
50
|
throw foo.bar;
|
|
49
51
|
```
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
</TabItem>
|
|
54
|
+
<TabItem value="✅ Correct">
|
|
52
55
|
|
|
53
56
|
```ts
|
|
54
57
|
throw new Error();
|
|
@@ -83,6 +86,9 @@ class CustomError extends Error {
|
|
|
83
86
|
throw new CustomError();
|
|
84
87
|
```
|
|
85
88
|
|
|
89
|
+
</TabItem>
|
|
90
|
+
</Tabs>
|
|
91
|
+
|
|
86
92
|
## Options
|
|
87
93
|
|
|
88
94
|
This rule adds the following options:
|
|
@@ -106,4 +112,4 @@ const defaultOptions: Options = {
|
|
|
106
112
|
};
|
|
107
113
|
```
|
|
108
114
|
|
|
109
|
-
|
|
115
|
+
{/* Intentionally Omitted: When Not To Use It */}
|
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
description: 'Disallow type aliases.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-type-alias** for documentation.
|
|
8
11
|
|
|
9
12
|
:::danger Deprecated
|
|
10
13
|
|
|
11
|
-
This rule has been deprecated in favour of the [`@typescript-eslint/consistent-type-definitions`](./consistent-type-definitions.
|
|
14
|
+
This rule has been deprecated in favour of the [`@typescript-eslint/consistent-type-definitions`](./consistent-type-definitions.mdx) rule.
|
|
12
15
|
TypeScript type aliases are a commonly necessary language feature; banning it altogether is oftentimes counterproductive.
|
|
13
16
|
|
|
14
17
|
:::
|
|
@@ -616,7 +619,7 @@ type Foo = Partial<Bar>;
|
|
|
616
619
|
type Foo = Omit<Bar, 'a' | 'b'>;
|
|
617
620
|
```
|
|
618
621
|
|
|
619
|
-
|
|
622
|
+
{/* Intentionally Omitted: When Not To Use It */}
|
|
620
623
|
|
|
621
624
|
## Further Reading
|
|
622
625
|
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow unnecessary equality comparisons against boolean literals.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-unnecessary-boolean-literal-compare** for documentation.
|
|
@@ -21,9 +24,8 @@ However, the implementation of the rule does not distinguish between strict and
|
|
|
21
24
|
Any example below that uses `===` would be treated the same way if `==` was used, and `!==` would be treated the same way if `!=` was used.
|
|
22
25
|
:::
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
### ❌ Incorrect
|
|
27
|
+
<Tabs>
|
|
28
|
+
<TabItem value="❌ Incorrect">
|
|
27
29
|
|
|
28
30
|
```ts
|
|
29
31
|
declare const someCondition: boolean;
|
|
@@ -31,7 +33,8 @@ if (someCondition === true) {
|
|
|
31
33
|
}
|
|
32
34
|
```
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
</TabItem>
|
|
37
|
+
<TabItem value="✅ Correct">
|
|
35
38
|
|
|
36
39
|
```ts
|
|
37
40
|
declare const someCondition: boolean;
|
|
@@ -47,6 +50,9 @@ if (someStringBoolean === true) {
|
|
|
47
50
|
}
|
|
48
51
|
```
|
|
49
52
|
|
|
53
|
+
</TabItem>
|
|
54
|
+
</Tabs>
|
|
55
|
+
|
|
50
56
|
## Options
|
|
51
57
|
|
|
52
58
|
This rule always checks comparisons between a boolean variable and a boolean
|
|
@@ -57,9 +63,8 @@ are **not** checked by default.
|
|
|
57
63
|
|
|
58
64
|
Examples of code for this rule with `{ allowComparingNullableBooleansToTrue: false }`:
|
|
59
65
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
#### ❌ Incorrect
|
|
66
|
+
<Tabs>
|
|
67
|
+
<TabItem value="❌ Incorrect">
|
|
63
68
|
|
|
64
69
|
```ts option='{ "allowComparingNullableBooleansToTrue": false }'
|
|
65
70
|
declare const someUndefinedCondition: boolean | undefined;
|
|
@@ -71,7 +76,8 @@ if (someNullCondition !== true) {
|
|
|
71
76
|
}
|
|
72
77
|
```
|
|
73
78
|
|
|
74
|
-
|
|
79
|
+
</TabItem>
|
|
80
|
+
<TabItem value="✅ Correct">
|
|
75
81
|
|
|
76
82
|
```ts option='{ "allowComparingNullableBooleansToTrue": false }'
|
|
77
83
|
declare const someUndefinedCondition: boolean | undefined;
|
|
@@ -83,13 +89,15 @@ if (!someNullCondition) {
|
|
|
83
89
|
}
|
|
84
90
|
```
|
|
85
91
|
|
|
92
|
+
</TabItem>
|
|
93
|
+
</Tabs>
|
|
94
|
+
|
|
86
95
|
### `allowComparingNullableBooleansToFalse`
|
|
87
96
|
|
|
88
97
|
Examples of code for this rule with `{ allowComparingNullableBooleansToFalse: false }`:
|
|
89
98
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
#### ❌ Incorrect
|
|
99
|
+
<Tabs>
|
|
100
|
+
<TabItem value="❌ Incorrect">
|
|
93
101
|
|
|
94
102
|
```ts option='{ "allowComparingNullableBooleansToFalse": false }'
|
|
95
103
|
declare const someUndefinedCondition: boolean | undefined;
|
|
@@ -101,7 +109,8 @@ if (someNullCondition !== false) {
|
|
|
101
109
|
}
|
|
102
110
|
```
|
|
103
111
|
|
|
104
|
-
|
|
112
|
+
</TabItem>
|
|
113
|
+
<TabItem value="✅ Correct">
|
|
105
114
|
|
|
106
115
|
```ts option='{ "allowComparingNullableBooleansToFalse": false }'
|
|
107
116
|
declare const someUndefinedCondition: boolean | undefined;
|
|
@@ -113,6 +122,9 @@ if (!(someNullCondition ?? true)) {
|
|
|
113
122
|
}
|
|
114
123
|
```
|
|
115
124
|
|
|
125
|
+
</TabItem>
|
|
126
|
+
</Tabs>
|
|
127
|
+
|
|
116
128
|
## Fixer
|
|
117
129
|
|
|
118
130
|
| Comparison | Fixer Output | Notes |
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow conditionals where the type is always truthy or always falsy.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-unnecessary-condition** for documentation.
|
|
@@ -17,9 +20,8 @@ The following expressions are checked:
|
|
|
17
20
|
|
|
18
21
|
## Examples
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
### ❌ Incorrect
|
|
23
|
+
<Tabs>
|
|
24
|
+
<TabItem value="❌ Incorrect">
|
|
23
25
|
|
|
24
26
|
```ts
|
|
25
27
|
function head<T>(items: T[]) {
|
|
@@ -47,7 +49,8 @@ function bar<T>(arg: string) {
|
|
|
47
49
|
].filter(t => t); // number[] is always truthy
|
|
48
50
|
```
|
|
49
51
|
|
|
50
|
-
|
|
52
|
+
</TabItem>
|
|
53
|
+
<TabItem value="✅ Correct">
|
|
51
54
|
|
|
52
55
|
```ts
|
|
53
56
|
function head<T>(items: T[]) {
|
|
@@ -71,6 +74,9 @@ function bar(arg?: string | null) {
|
|
|
71
74
|
[0, 1, 2, 3].filter(t => t); // number can be truthy or falsy
|
|
72
75
|
```
|
|
73
76
|
|
|
77
|
+
</TabItem>
|
|
78
|
+
</Tabs>
|
|
79
|
+
|
|
74
80
|
## Options
|
|
75
81
|
|
|
76
82
|
### `allowConstantLoopConditions`
|
|
@@ -116,4 +122,4 @@ if (condition) {
|
|
|
116
122
|
## Related To
|
|
117
123
|
|
|
118
124
|
- ESLint: [no-constant-condition](https://eslint.org/docs/rules/no-constant-condition) - `no-unnecessary-condition` is essentially a stronger version of `no-constant-condition`, but requires type information.
|
|
119
|
-
- [strict-boolean-expressions](./strict-boolean-expressions.
|
|
125
|
+
- [strict-boolean-expressions](./strict-boolean-expressions.mdx) - a more opinionated version of `no-unnecessary-condition`. `strict-boolean-expressions` enforces a specific code style, while `no-unnecessary-condition` is about correctness.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow unnecessary namespace qualifiers.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-unnecessary-qualifier** for documentation.
|
|
@@ -12,9 +15,8 @@ This rule reports when an enum or namespace qualifier is unnecessary.
|
|
|
12
15
|
|
|
13
16
|
## Examples
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
### ❌ Incorrect
|
|
18
|
+
<Tabs>
|
|
19
|
+
<TabItem value="❌ Incorrect">
|
|
18
20
|
|
|
19
21
|
```ts
|
|
20
22
|
enum A {
|
|
@@ -30,7 +32,8 @@ namespace A {
|
|
|
30
32
|
}
|
|
31
33
|
```
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
</TabItem>
|
|
36
|
+
<TabItem value="✅ Correct">
|
|
34
37
|
|
|
35
38
|
```ts
|
|
36
39
|
enum A {
|
|
@@ -46,6 +49,9 @@ namespace A {
|
|
|
46
49
|
}
|
|
47
50
|
```
|
|
48
51
|
|
|
52
|
+
</TabItem>
|
|
53
|
+
</Tabs>
|
|
54
|
+
|
|
49
55
|
## When Not To Use It
|
|
50
56
|
|
|
51
57
|
If you explicitly prefer to use fully qualified names, such as for explicitness, then you don't need to use this rule.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow type arguments that are equal to the default.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-unnecessary-type-arguments** for documentation.
|
|
@@ -20,9 +23,8 @@ This rule reports when an explicitly specified type argument is the default for
|
|
|
20
23
|
|
|
21
24
|
## Examples
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
### ❌ Incorrect
|
|
26
|
+
<Tabs>
|
|
27
|
+
<TabItem value="❌ Incorrect">
|
|
26
28
|
|
|
27
29
|
```ts
|
|
28
30
|
function f<T = number>() {}
|
|
@@ -46,7 +48,8 @@ interface I<T = number> {}
|
|
|
46
48
|
class Impl implements I<number> {}
|
|
47
49
|
```
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
</TabItem>
|
|
52
|
+
<TabItem value="✅ Correct">
|
|
50
53
|
|
|
51
54
|
```ts
|
|
52
55
|
function f<T = number>() {}
|
|
@@ -74,6 +77,9 @@ interface I<T = number> {}
|
|
|
74
77
|
class Impl implements I<string> {}
|
|
75
78
|
```
|
|
76
79
|
|
|
80
|
+
</TabItem>
|
|
81
|
+
</Tabs>
|
|
82
|
+
|
|
77
83
|
## When Not To Use It
|
|
78
84
|
|
|
79
85
|
If you prefer explicitly specifying type parameters even when they are equal to the default, you can skip this rule.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow type assertions that do not change the type of an expression.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-unnecessary-type-assertion** for documentation.
|
|
@@ -12,9 +15,8 @@ This rule reports when a type assertion does not change the type of an expressio
|
|
|
12
15
|
|
|
13
16
|
## Examples
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
### ❌ Incorrect
|
|
18
|
+
<Tabs>
|
|
19
|
+
<TabItem value="❌ Incorrect">
|
|
18
20
|
|
|
19
21
|
```ts
|
|
20
22
|
const foo = 3;
|
|
@@ -41,7 +43,8 @@ function foo(x: number): number {
|
|
|
41
43
|
}
|
|
42
44
|
```
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
</TabItem>
|
|
47
|
+
<TabItem value="✅ Correct">
|
|
45
48
|
|
|
46
49
|
```ts
|
|
47
50
|
const foo = <number>3;
|
|
@@ -61,6 +64,9 @@ function foo(x: number | undefined): number {
|
|
|
61
64
|
}
|
|
62
65
|
```
|
|
63
66
|
|
|
67
|
+
</TabItem>
|
|
68
|
+
</Tabs>
|
|
69
|
+
|
|
64
70
|
## Options
|
|
65
71
|
|
|
66
72
|
### `typesToIgnore`
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow unnecessary constraints on generic types.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-unnecessary-type-constraint** for documentation.
|
|
@@ -12,9 +15,8 @@ It is therefore redundant to `extend` from `any` or `unknown`.
|
|
|
12
15
|
|
|
13
16
|
## Examples
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
### ❌ Incorrect
|
|
18
|
+
<Tabs>
|
|
19
|
+
<TabItem value="❌ Incorrect">
|
|
18
20
|
|
|
19
21
|
```ts
|
|
20
22
|
interface FooAny<T extends any> {}
|
|
@@ -34,7 +36,8 @@ const QuuxAny = <T extends any>() => {};
|
|
|
34
36
|
function QuuzAny<T extends any>() {}
|
|
35
37
|
```
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
</TabItem>
|
|
40
|
+
<TabItem value="✅ Correct">
|
|
38
41
|
|
|
39
42
|
```ts
|
|
40
43
|
interface Foo<T> {}
|
|
@@ -50,6 +53,9 @@ const Quux = <T>() => {};
|
|
|
50
53
|
function Quuz<T>() {}
|
|
51
54
|
```
|
|
52
55
|
|
|
56
|
+
</TabItem>
|
|
57
|
+
</Tabs>
|
|
58
|
+
|
|
53
59
|
## When Not To Use It
|
|
54
60
|
|
|
55
61
|
If you don't care about the specific styles of your type constraints, or never use them in the first place, then you will not need this rule.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow calling a function with a value with type `any`.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-unsafe-argument** for documentation.
|
|
@@ -20,9 +23,8 @@ For example, it will error if you pass `Set<any>` as an argument to a parameter
|
|
|
20
23
|
|
|
21
24
|
## Examples
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
### ❌ Incorrect
|
|
26
|
+
<Tabs>
|
|
27
|
+
<TabItem value="❌ Incorrect">
|
|
26
28
|
|
|
27
29
|
```ts
|
|
28
30
|
declare function foo(arg1: string, arg2: number, arg3: string): void;
|
|
@@ -49,7 +51,8 @@ declare function baz(arg1: Set<string>, arg2: Map<string, string>): void;
|
|
|
49
51
|
foo(new Set<any>(), new Map<any, string>());
|
|
50
52
|
```
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
</TabItem>
|
|
55
|
+
<TabItem value="✅ Correct">
|
|
53
56
|
|
|
54
57
|
```ts
|
|
55
58
|
declare function foo(arg1: string, arg2: number, arg3: string): void;
|
|
@@ -67,7 +70,8 @@ declare function baz(arg1: Set<string>, arg2: Map<string, string>): void;
|
|
|
67
70
|
foo(new Set<string>(), new Map<string, string>());
|
|
68
71
|
```
|
|
69
72
|
|
|
70
|
-
|
|
73
|
+
</TabItem>
|
|
74
|
+
</Tabs>
|
|
71
75
|
|
|
72
76
|
There are cases where the rule allows passing an argument of `any` to `unknown`.
|
|
73
77
|
|
|
@@ -86,8 +90,8 @@ You might consider using [ESLint disable comments](https://eslint.org/docs/lates
|
|
|
86
90
|
|
|
87
91
|
## Related To
|
|
88
92
|
|
|
89
|
-
- [`no-explicit-any`](./no-explicit-any.
|
|
90
|
-
- [`no-unsafe-assignment`](./no-unsafe-assignment.
|
|
91
|
-
- [`no-unsafe-call`](./no-unsafe-call.
|
|
92
|
-
- [`no-unsafe-member-access`](./no-unsafe-member-access.
|
|
93
|
-
- [`no-unsafe-return`](./no-unsafe-return.
|
|
93
|
+
- [`no-explicit-any`](./no-explicit-any.mdx)
|
|
94
|
+
- [`no-unsafe-assignment`](./no-unsafe-assignment.mdx)
|
|
95
|
+
- [`no-unsafe-call`](./no-unsafe-call.mdx)
|
|
96
|
+
- [`no-unsafe-member-access`](./no-unsafe-member-access.mdx)
|
|
97
|
+
- [`no-unsafe-return`](./no-unsafe-return.mdx)
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow assigning a value with type `any` to variables and properties.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-unsafe-assignment** for documentation.
|
|
@@ -19,9 +22,8 @@ For example, it will error if you assign `Set<any>` to a variable declared as `S
|
|
|
19
22
|
|
|
20
23
|
## Examples
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
### ❌ Incorrect
|
|
25
|
+
<Tabs>
|
|
26
|
+
<TabItem value="❌ Incorrect">
|
|
25
27
|
|
|
26
28
|
```ts
|
|
27
29
|
const x = 1 as any,
|
|
@@ -46,7 +48,8 @@ const x: Set<string[]> = new Set<any[]>();
|
|
|
46
48
|
const x: Set<Set<Set<string>>> = new Set<Set<Set<any>>>();
|
|
47
49
|
```
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
</TabItem>
|
|
52
|
+
<TabItem value="✅ Correct">
|
|
50
53
|
|
|
51
54
|
```ts
|
|
52
55
|
const x = 1,
|
|
@@ -69,7 +72,8 @@ const x: Set<string[]> = new Set<string[]>();
|
|
|
69
72
|
const x: Set<Set<Set<string>>> = new Set<Set<Set<string>>>();
|
|
70
73
|
```
|
|
71
74
|
|
|
72
|
-
|
|
75
|
+
</TabItem>
|
|
76
|
+
</Tabs>
|
|
73
77
|
|
|
74
78
|
There are cases where the rule allows assignment of `any` to `unknown`.
|
|
75
79
|
|
|
@@ -89,8 +93,8 @@ You might consider using [ESLint disable comments](https://eslint.org/docs/lates
|
|
|
89
93
|
|
|
90
94
|
## Related To
|
|
91
95
|
|
|
92
|
-
- [`no-explicit-any`](./no-explicit-any.
|
|
93
|
-
- [`no-unsafe-argument`](./no-unsafe-argument.
|
|
94
|
-
- [`no-unsafe-call`](./no-unsafe-call.
|
|
95
|
-
- [`no-unsafe-member-access`](./no-unsafe-member-access.
|
|
96
|
-
- [`no-unsafe-return`](./no-unsafe-return.
|
|
96
|
+
- [`no-explicit-any`](./no-explicit-any.mdx)
|
|
97
|
+
- [`no-unsafe-argument`](./no-unsafe-argument.mdx)
|
|
98
|
+
- [`no-unsafe-call`](./no-unsafe-call.mdx)
|
|
99
|
+
- [`no-unsafe-member-access`](./no-unsafe-member-access.mdx)
|
|
100
|
+
- [`no-unsafe-return`](./no-unsafe-return.mdx)
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow calling a value with type `any`.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-unsafe-call** for documentation.
|
|
@@ -16,9 +19,8 @@ This rule disallows calling any value that is typed as `any`.
|
|
|
16
19
|
|
|
17
20
|
## Examples
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
### ❌ Incorrect
|
|
22
|
+
<Tabs>
|
|
23
|
+
<TabItem value="❌ Incorrect">
|
|
22
24
|
|
|
23
25
|
```ts
|
|
24
26
|
declare const anyVar: any;
|
|
@@ -37,7 +39,8 @@ anyVar`foo`;
|
|
|
37
39
|
nestedAny.prop`foo`;
|
|
38
40
|
```
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
</TabItem>
|
|
43
|
+
<TabItem value="✅ Correct">
|
|
41
44
|
|
|
42
45
|
```ts
|
|
43
46
|
declare const typedVar: () => void;
|
|
@@ -53,6 +56,9 @@ new Map();
|
|
|
53
56
|
String.raw`foo`;
|
|
54
57
|
```
|
|
55
58
|
|
|
59
|
+
</TabItem>
|
|
60
|
+
</Tabs>
|
|
61
|
+
|
|
56
62
|
## When Not To Use It
|
|
57
63
|
|
|
58
64
|
If your codebase has many existing `any`s or areas of unsafe code, it may be difficult to enable this rule.
|
|
@@ -61,8 +67,8 @@ You might consider using [ESLint disable comments](https://eslint.org/docs/lates
|
|
|
61
67
|
|
|
62
68
|
## Related To
|
|
63
69
|
|
|
64
|
-
- [`no-explicit-any`](./no-explicit-any.
|
|
65
|
-
- [`no-unsafe-argument`](./no-unsafe-argument.
|
|
66
|
-
- [`no-unsafe-assignment`](./no-unsafe-assignment.
|
|
67
|
-
- [`no-unsafe-member-access`](./no-unsafe-member-access.
|
|
68
|
-
- [`no-unsafe-return`](./no-unsafe-return.
|
|
70
|
+
- [`no-explicit-any`](./no-explicit-any.mdx)
|
|
71
|
+
- [`no-unsafe-argument`](./no-unsafe-argument.mdx)
|
|
72
|
+
- [`no-unsafe-assignment`](./no-unsafe-assignment.mdx)
|
|
73
|
+
- [`no-unsafe-member-access`](./no-unsafe-member-access.mdx)
|
|
74
|
+
- [`no-unsafe-return`](./no-unsafe-return.mdx)
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow unsafe declaration merging.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-unsafe-declaration-merging** for documentation.
|
|
@@ -25,9 +28,8 @@ foo.nums.push(1); // Runtime Error: Cannot read properties of undefined.
|
|
|
25
28
|
|
|
26
29
|
## Examples
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
### ❌ Incorrect
|
|
31
|
+
<Tabs>
|
|
32
|
+
<TabItem value="❌ Incorrect">
|
|
31
33
|
|
|
32
34
|
```ts
|
|
33
35
|
interface Foo {}
|
|
@@ -35,7 +37,8 @@ interface Foo {}
|
|
|
35
37
|
class Foo {}
|
|
36
38
|
```
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
</TabItem>
|
|
41
|
+
<TabItem value="✅ Correct">
|
|
39
42
|
|
|
40
43
|
```ts
|
|
41
44
|
interface Foo {}
|
|
@@ -49,6 +52,9 @@ namespace Qux {}
|
|
|
49
52
|
function Qux() {}
|
|
50
53
|
```
|
|
51
54
|
|
|
55
|
+
</TabItem>
|
|
56
|
+
</Tabs>
|
|
57
|
+
|
|
52
58
|
## When Not To Use It
|
|
53
59
|
|
|
54
60
|
If your project intentionally defines classes and interfaces with unsafe declaration merging patterns, this rule might not be for you.
|