@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.
Files changed (183) hide show
  1. package/dist/configs/all.js +1 -0
  2. package/dist/configs/all.js.map +1 -1
  3. package/dist/configs/disable-type-checked.js +1 -0
  4. package/dist/configs/disable-type-checked.js.map +1 -1
  5. package/dist/configs/strict-type-checked-only.js +23 -3
  6. package/dist/configs/strict-type-checked-only.js.map +1 -1
  7. package/dist/configs/strict-type-checked.js +27 -4
  8. package/dist/configs/strict-type-checked.js.map +1 -1
  9. package/dist/configs/strict.js +4 -1
  10. package/dist/configs/strict.js.map +1 -1
  11. package/dist/rules/ban-ts-comment.js +4 -1
  12. package/dist/rules/ban-ts-comment.js.map +1 -1
  13. package/dist/rules/consistent-type-imports.js +1 -0
  14. package/dist/rules/consistent-type-imports.js.map +1 -1
  15. package/dist/rules/index.js +2 -0
  16. package/dist/rules/index.js.map +1 -1
  17. package/dist/rules/no-floating-promises.js +4 -1
  18. package/dist/rules/no-floating-promises.js.map +1 -1
  19. package/dist/rules/no-misused-promises.js +1 -1
  20. package/dist/rules/no-misused-promises.js.map +1 -1
  21. package/dist/rules/no-redundant-type-constituents.js +42 -0
  22. package/dist/rules/no-redundant-type-constituents.js.map +1 -1
  23. package/dist/rules/no-unnecessary-qualifier.js +1 -1
  24. package/dist/rules/no-unnecessary-qualifier.js.map +1 -1
  25. package/dist/rules/no-unsafe-argument.js +1 -25
  26. package/dist/rules/no-unsafe-argument.js.map +1 -1
  27. package/dist/rules/no-unused-expressions.js +6 -2
  28. package/dist/rules/no-unused-expressions.js.map +1 -1
  29. package/dist/rules/restrict-plus-operands.js +12 -1
  30. package/dist/rules/restrict-plus-operands.js.map +1 -1
  31. package/dist/rules/restrict-template-expressions.js +52 -87
  32. package/dist/rules/restrict-template-expressions.js.map +1 -1
  33. package/dist/rules/use-unknown-in-catch-callback-variable.js +283 -0
  34. package/dist/rules/use-unknown-in-catch-callback-variable.js.map +1 -0
  35. package/dist/util/misc.js +10 -1
  36. package/dist/util/misc.js.map +1 -1
  37. package/docs/rules/TEMPLATE.md +10 -4
  38. package/docs/rules/{adjacent-overload-signatures.md → adjacent-overload-signatures.mdx} +11 -5
  39. package/docs/rules/{array-type.md → array-type.mdx} +24 -12
  40. package/docs/rules/{await-thenable.md → await-thenable.mdx} +10 -4
  41. package/docs/rules/{ban-ts-comment.md → ban-ts-comment.mdx} +32 -18
  42. package/docs/rules/{ban-tslint-comment.md → ban-tslint-comment.mdx} +10 -4
  43. package/docs/rules/{ban-types.md → ban-types.mdx} +11 -5
  44. package/docs/rules/{block-spacing.md → block-spacing.mdx} +3 -0
  45. package/docs/rules/{brace-style.md → brace-style.mdx} +3 -0
  46. package/docs/rules/camelcase.md +3 -5
  47. package/docs/rules/{class-literal-property-style.md → class-literal-property-style.mdx} +18 -11
  48. package/docs/rules/{class-methods-use-this.md → class-methods-use-this.mdx} +12 -6
  49. package/docs/rules/{comma-dangle.md → comma-dangle.mdx} +3 -0
  50. package/docs/rules/{comma-spacing.md → comma-spacing.mdx} +3 -0
  51. package/docs/rules/{consistent-generic-constructors.md → consistent-generic-constructors.mdx} +17 -8
  52. package/docs/rules/{consistent-indexed-object-style.md → consistent-indexed-object-style.mdx} +17 -8
  53. package/docs/rules/{consistent-return.md → consistent-return.mdx} +10 -4
  54. package/docs/rules/{consistent-type-assertions.md → consistent-type-assertions.mdx} +15 -10
  55. package/docs/rules/{consistent-type-definitions.md → consistent-type-definitions.mdx} +17 -8
  56. package/docs/rules/{consistent-type-exports.md → consistent-type-exports.mdx} +17 -8
  57. package/docs/rules/{consistent-type-imports.md → consistent-type-imports.mdx} +13 -8
  58. package/docs/rules/{default-param-last.md → default-param-last.mdx} +10 -4
  59. package/docs/rules/{dot-notation.md → dot-notation.mdx} +3 -0
  60. package/docs/rules/{explicit-function-return-type.md → explicit-function-return-type.mdx} +59 -32
  61. package/docs/rules/{explicit-member-accessibility.md → explicit-member-accessibility.mdx} +3 -0
  62. package/docs/rules/{explicit-module-boundary-types.md → explicit-module-boundary-types.mdx} +39 -21
  63. package/docs/rules/{func-call-spacing.md → func-call-spacing.mdx} +3 -0
  64. package/docs/rules/{indent.md → indent.mdx} +3 -0
  65. package/docs/rules/{init-declarations.md → init-declarations.mdx} +3 -0
  66. package/docs/rules/{key-spacing.md → key-spacing.mdx} +3 -0
  67. package/docs/rules/{keyword-spacing.md → keyword-spacing.mdx} +3 -0
  68. package/docs/rules/{lines-around-comment.md → lines-around-comment.mdx} +3 -0
  69. package/docs/rules/{lines-between-class-members.md → lines-between-class-members.mdx} +3 -0
  70. package/docs/rules/{max-params.md → max-params.mdx} +3 -0
  71. package/docs/rules/{member-delimiter-style.md → member-delimiter-style.mdx} +13 -7
  72. package/docs/rules/{member-ordering.md → member-ordering.mdx} +92 -56
  73. package/docs/rules/{method-signature-style.md → method-signature-style.mdx} +17 -8
  74. package/docs/rules/{naming-convention.md → naming-convention.mdx} +3 -0
  75. package/docs/rules/{no-array-constructor.md → no-array-constructor.mdx} +10 -4
  76. package/docs/rules/{no-array-delete.md → no-array-delete.mdx} +9 -5
  77. package/docs/rules/{no-base-to-string.md → no-base-to-string.mdx} +12 -6
  78. package/docs/rules/{no-confusing-non-null-assertion.md → no-confusing-non-null-assertion.mdx} +11 -5
  79. package/docs/rules/{no-confusing-void-expression.md → no-confusing-void-expression.mdx} +10 -4
  80. package/docs/rules/{no-dupe-class-members.md → no-dupe-class-members.mdx} +4 -1
  81. package/docs/rules/{no-duplicate-enum-values.md → no-duplicate-enum-values.mdx} +10 -4
  82. package/docs/rules/{no-duplicate-imports.md → no-duplicate-imports.mdx} +1 -1
  83. package/docs/rules/{no-duplicate-type-constituents.md → no-duplicate-type-constituents.mdx} +10 -4
  84. package/docs/rules/{no-dynamic-delete.md → no-dynamic-delete.mdx} +10 -4
  85. package/docs/rules/{no-empty-function.md → no-empty-function.mdx} +3 -0
  86. package/docs/rules/{no-empty-interface.md → no-empty-interface.mdx} +9 -5
  87. package/docs/rules/{no-explicit-any.md → no-explicit-any.mdx} +15 -9
  88. package/docs/rules/{no-extra-non-null-assertion.md → no-extra-non-null-assertion.mdx} +11 -5
  89. package/docs/rules/{no-extra-parens.md → no-extra-parens.mdx} +3 -0
  90. package/docs/rules/{no-extra-semi.md → no-extra-semi.mdx} +3 -0
  91. package/docs/rules/{no-extraneous-class.md → no-extraneous-class.mdx} +61 -33
  92. package/docs/rules/{no-floating-promises.md → no-floating-promises.mdx} +12 -6
  93. package/docs/rules/{no-for-in-array.md → no-for-in-array.mdx} +10 -4
  94. package/docs/rules/{no-implied-eval.md → no-implied-eval.mdx} +10 -4
  95. package/docs/rules/{no-import-type-side-effects.md → no-import-type-side-effects.mdx} +12 -6
  96. package/docs/rules/{no-inferrable-types.md → no-inferrable-types.mdx} +9 -5
  97. package/docs/rules/{no-invalid-this.md → no-invalid-this.mdx} +4 -1
  98. package/docs/rules/{no-invalid-void-type.md → no-invalid-void-type.mdx} +10 -4
  99. package/docs/rules/{no-loop-func.md → no-loop-func.mdx} +3 -0
  100. package/docs/rules/{no-loss-of-precision.md → no-loss-of-precision.mdx} +3 -0
  101. package/docs/rules/{no-magic-numbers.md → no-magic-numbers.mdx} +3 -0
  102. package/docs/rules/{no-meaningless-void-operator.md → no-meaningless-void-operator.mdx} +12 -4
  103. package/docs/rules/{no-misused-new.md → no-misused-new.mdx} +10 -4
  104. package/docs/rules/{no-misused-promises.md → no-misused-promises.mdx} +24 -16
  105. package/docs/rules/{no-mixed-enums.md → no-mixed-enums.mdx} +14 -6
  106. package/docs/rules/{no-namespace.md → no-namespace.mdx} +29 -18
  107. package/docs/rules/{no-non-null-asserted-nullish-coalescing.md → no-non-null-asserted-nullish-coalescing.mdx} +10 -4
  108. package/docs/rules/{no-non-null-asserted-optional-chain.md → no-non-null-asserted-optional-chain.mdx} +10 -4
  109. package/docs/rules/{no-non-null-assertion.md → no-non-null-assertion.mdx} +10 -4
  110. package/docs/rules/{no-redeclare.md → no-redeclare.mdx} +4 -1
  111. package/docs/rules/{no-redundant-type-constituents.md → no-redundant-type-constituents.mdx} +10 -4
  112. package/docs/rules/{no-require-imports.md → no-require-imports.mdx} +18 -9
  113. package/docs/rules/{no-restricted-imports.md → no-restricted-imports.mdx} +10 -4
  114. package/docs/rules/{no-shadow.md → no-shadow.mdx} +4 -1
  115. package/docs/rules/{no-this-alias.md → no-this-alias.mdx} +24 -12
  116. package/docs/rules/{no-throw-literal.md → no-throw-literal.mdx} +11 -5
  117. package/docs/rules/{no-type-alias.md → no-type-alias.mdx} +5 -2
  118. package/docs/rules/{no-unnecessary-boolean-literal-compare.md → no-unnecessary-boolean-literal-compare.mdx} +24 -12
  119. package/docs/rules/{no-unnecessary-condition.md → no-unnecessary-condition.mdx} +11 -5
  120. package/docs/rules/{no-unnecessary-qualifier.md → no-unnecessary-qualifier.mdx} +10 -4
  121. package/docs/rules/{no-unnecessary-type-arguments.md → no-unnecessary-type-arguments.mdx} +10 -4
  122. package/docs/rules/{no-unnecessary-type-assertion.md → no-unnecessary-type-assertion.mdx} +10 -4
  123. package/docs/rules/{no-unnecessary-type-constraint.md → no-unnecessary-type-constraint.mdx} +10 -4
  124. package/docs/rules/{no-unsafe-argument.md → no-unsafe-argument.mdx} +14 -10
  125. package/docs/rules/{no-unsafe-assignment.md → no-unsafe-assignment.mdx} +14 -10
  126. package/docs/rules/{no-unsafe-call.md → no-unsafe-call.mdx} +15 -9
  127. package/docs/rules/{no-unsafe-declaration-merging.md → no-unsafe-declaration-merging.mdx} +10 -4
  128. package/docs/rules/{no-unsafe-enum-comparison.md → no-unsafe-enum-comparison.mdx} +9 -5
  129. package/docs/rules/{no-unsafe-member-access.md → no-unsafe-member-access.mdx} +15 -9
  130. package/docs/rules/{no-unsafe-return.md → no-unsafe-return.mdx} +14 -10
  131. package/docs/rules/{no-unsafe-unary-minus.md → no-unsafe-unary-minus.mdx} +11 -5
  132. package/docs/rules/{no-unused-expressions.md → no-unused-expressions.mdx} +3 -0
  133. package/docs/rules/{no-unused-vars.md → no-unused-vars.mdx} +3 -0
  134. package/docs/rules/{no-use-before-define.md → no-use-before-define.mdx} +10 -4
  135. package/docs/rules/{no-useless-constructor.md → no-useless-constructor.mdx} +3 -0
  136. package/docs/rules/{no-useless-empty-export.md → no-useless-empty-export.mdx} +10 -4
  137. package/docs/rules/{no-useless-template-literals.md → no-useless-template-literals.mdx} +10 -6
  138. package/docs/rules/{no-var-requires.md → no-var-requires.mdx} +18 -9
  139. package/docs/rules/{non-nullable-type-assertion-style.md → non-nullable-type-assertion-style.mdx} +10 -4
  140. package/docs/rules/{object-curly-spacing.md → object-curly-spacing.mdx} +3 -0
  141. package/docs/rules/{padding-line-between-statements.md → padding-line-between-statements.mdx} +3 -0
  142. package/docs/rules/{parameter-properties.md → parameter-properties.mdx} +66 -36
  143. package/docs/rules/{prefer-as-const.md → prefer-as-const.mdx} +9 -5
  144. package/docs/rules/{prefer-destructuring.md → prefer-destructuring.mdx} +23 -12
  145. package/docs/rules/{prefer-enum-initializers.md → prefer-enum-initializers.mdx} +10 -4
  146. package/docs/rules/{prefer-find.md → prefer-find.mdx} +10 -4
  147. package/docs/rules/{prefer-for-of.md → prefer-for-of.mdx} +11 -5
  148. package/docs/rules/{prefer-function-type.md → prefer-function-type.mdx} +10 -4
  149. package/docs/rules/{prefer-includes.md → prefer-includes.mdx} +11 -5
  150. package/docs/rules/{prefer-literal-enum-member.md → prefer-literal-enum-member.mdx} +16 -9
  151. package/docs/rules/{prefer-namespace-keyword.md → prefer-namespace-keyword.mdx} +9 -5
  152. package/docs/rules/{prefer-nullish-coalescing.md → prefer-nullish-coalescing.mdx} +3 -0
  153. package/docs/rules/{prefer-optional-chain.md → prefer-optional-chain.mdx} +58 -33
  154. package/docs/rules/{prefer-promise-reject-errors.md → prefer-promise-reject-errors.mdx} +10 -4
  155. package/docs/rules/{prefer-readonly-parameter-types.md → prefer-readonly-parameter-types.mdx} +36 -22
  156. package/docs/rules/{prefer-readonly.md → prefer-readonly.mdx} +17 -8
  157. package/docs/rules/{prefer-reduce-type-parameter.md → prefer-reduce-type-parameter.mdx} +10 -4
  158. package/docs/rules/{prefer-regexp-exec.md → prefer-regexp-exec.mdx} +10 -4
  159. package/docs/rules/{prefer-return-this-type.md → prefer-return-this-type.mdx} +10 -4
  160. package/docs/rules/{prefer-string-starts-ends-with.md → prefer-string-starts-ends-with.mdx} +9 -5
  161. package/docs/rules/{prefer-ts-expect-error.md → prefer-ts-expect-error.mdx} +10 -4
  162. package/docs/rules/{promise-function-async.md → promise-function-async.mdx} +24 -12
  163. package/docs/rules/{quotes.md → quotes.mdx} +3 -0
  164. package/docs/rules/{require-array-sort-compare.md → require-array-sort-compare.mdx} +17 -8
  165. package/docs/rules/{require-await.md → require-await.mdx} +3 -0
  166. package/docs/rules/{restrict-plus-operands.md → restrict-plus-operands.mdx} +54 -30
  167. package/docs/rules/{restrict-template-expressions.md → restrict-template-expressions.mdx} +24 -9
  168. package/docs/rules/{return-await.md → return-await.mdx} +24 -12
  169. package/docs/rules/{semi.md → semi.mdx} +4 -1
  170. package/docs/rules/{sort-type-constituents.md → sort-type-constituents.mdx} +31 -16
  171. package/docs/rules/{space-before-blocks.md → space-before-blocks.mdx} +10 -4
  172. package/docs/rules/{space-before-function-paren.md → space-before-function-paren.mdx} +3 -0
  173. package/docs/rules/{space-infix-ops.md → space-infix-ops.mdx} +3 -0
  174. package/docs/rules/{strict-boolean-expressions.md → strict-boolean-expressions.mdx} +11 -5
  175. package/docs/rules/{switch-exhaustiveness-check.md → switch-exhaustiveness-check.mdx} +19 -14
  176. package/docs/rules/{triple-slash-reference.md → triple-slash-reference.mdx} +30 -17
  177. package/docs/rules/{type-annotation-spacing.md → type-annotation-spacing.mdx} +49 -31
  178. package/docs/rules/{typedef.md → typedef.mdx} +60 -33
  179. package/docs/rules/{unbound-method.md → unbound-method.mdx} +12 -6
  180. package/docs/rules/{unified-signatures.md → unified-signatures.mdx} +18 -9
  181. package/docs/rules/use-unknown-in-catch-callback-variable.mdx +84 -0
  182. package/package.json +8 -8
  183. /package/docs/rules/{no-parameter-properties.md → no-parameter-properties.mdx} +0 -0
@@ -2,6 +2,9 @@
2
2
  description: 'Require type annotations in certain places.'
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/typedef** for documentation.
@@ -25,7 +28,7 @@ class ContainsText {
25
28
  }
26
29
  ```
27
30
 
28
- > To enforce type definitions existing on call signatures, use [`explicit-function-return-type`](./explicit-function-return-type.md), or [`explicit-module-boundary-types`](./explicit-module-boundary-types.md).
31
+ > To enforce type definitions existing on call signatures, use [`explicit-function-return-type`](./explicit-function-return-type.mdx), or [`explicit-module-boundary-types`](./explicit-module-boundary-types.mdx).
29
32
 
30
33
  :::caution
31
34
 
@@ -63,16 +66,16 @@ Whether to enforce type annotations on variables declared using array destructur
63
66
 
64
67
  Examples of code with `{ "arrayDestructuring": true }`:
65
68
 
66
- <!--tabs-->
67
-
68
- #### ❌ Incorrect
69
+ <Tabs>
70
+ <TabItem value="❌ Incorrect">
69
71
 
70
72
  ```ts option='{ "arrayDestructuring": true }'
71
73
  const [a] = [1];
72
74
  const [b, c] = [1, 2];
73
75
  ```
74
76
 
75
- #### ✅ Correct
77
+ </TabItem>
78
+ <TabItem value="✅ Correct">
76
79
 
77
80
  ```ts option='{ "arrayDestructuring": true }'
78
81
  const [a]: number[] = [1];
@@ -83,15 +86,17 @@ for (const [key, val] of new Map([['key', 1]])) {
83
86
  }
84
87
  ```
85
88
 
89
+ </TabItem>
90
+ </Tabs>
91
+
86
92
  ### `arrowParameter`
87
93
 
88
94
  Whether to enforce type annotations for parameters of arrow functions.
89
95
 
90
96
  Examples of code with `{ "arrowParameter": true }`:
91
97
 
92
- <!--tabs-->
93
-
94
- #### ❌ Incorrect
98
+ <Tabs>
99
+ <TabItem value="❌ Incorrect">
95
100
 
96
101
  ```ts option='{ "arrowParameter": true }'
97
102
  const logsSize = size => console.log(size);
@@ -103,7 +108,8 @@ const mapper = {
103
108
  };
104
109
  ```
105
110
 
106
- #### ✅ Correct
111
+ </TabItem>
112
+ <TabItem value="✅ Correct">
107
113
 
108
114
  ```ts option='{ "arrowParameter": true }'
109
115
  const logsSize = (size: number) => console.log(size);
@@ -115,15 +121,17 @@ const mapper = {
115
121
  };
116
122
  ```
117
123
 
124
+ </TabItem>
125
+ </Tabs>
126
+
118
127
  ### `memberVariableDeclaration`
119
128
 
120
129
  Whether to enforce type annotations on member variables of classes.
121
130
 
122
131
  Examples of code with `{ "memberVariableDeclaration": true }`:
123
132
 
124
- <!--tabs-->
125
-
126
- #### ❌ Incorrect
133
+ <Tabs>
134
+ <TabItem value="❌ Incorrect">
127
135
 
128
136
  ```ts option='{ "memberVariableDeclaration": true }'
129
137
  class ContainsText {
@@ -132,7 +140,8 @@ class ContainsText {
132
140
  }
133
141
  ```
134
142
 
135
- #### ✅ Correct
143
+ </TabItem>
144
+ <TabItem value="✅ Correct">
136
145
 
137
146
  ```ts option='{ "memberVariableDeclaration": true }'
138
147
  class ContainsText {
@@ -141,22 +150,25 @@ class ContainsText {
141
150
  }
142
151
  ```
143
152
 
153
+ </TabItem>
154
+ </Tabs>
155
+
144
156
  ### `objectDestructuring`
145
157
 
146
158
  Whether to enforce type annotations on variables declared using object destructuring.
147
159
 
148
160
  Examples of code with `{ "objectDestructuring": true }`:
149
161
 
150
- <!--tabs-->
151
-
152
- #### ❌ Incorrect
162
+ <Tabs>
163
+ <TabItem value="❌ Incorrect">
153
164
 
154
165
  ```ts option='{ "objectDestructuring": true }'
155
166
  const { length } = 'text';
156
167
  const [b, c] = Math.random() ? [1, 2] : [3, 4];
157
168
  ```
158
169
 
159
- #### ✅ Correct
170
+ </TabItem>
171
+ <TabItem value="✅ Correct">
160
172
 
161
173
  ```ts option='{ "objectDestructuring": true }'
162
174
  const { length }: { length: number } = 'text';
@@ -166,15 +178,17 @@ for (const { key, val } of [{ key: 'key', val: 1 }]) {
166
178
  }
167
179
  ```
168
180
 
181
+ </TabItem>
182
+ </Tabs>
183
+
169
184
  ### `parameter`
170
185
 
171
186
  Whether to enforce type annotations for parameters of functions and methods.
172
187
 
173
188
  Examples of code with `{ "parameter": true }`:
174
189
 
175
- <!--tabs-->
176
-
177
- #### ❌ Incorrect
190
+ <Tabs>
191
+ <TabItem value="❌ Incorrect">
178
192
 
179
193
  ```ts option='{ "parameter": true }'
180
194
  function logsSize(size): void {
@@ -202,7 +216,8 @@ class Logger {
202
216
  }
203
217
  ```
204
218
 
205
- #### ✅ Correct
219
+ </TabItem>
220
+ <TabItem value="✅ Correct">
206
221
 
207
222
  ```ts option='{ "parameter": true }'
208
223
  function logsSize(size: number): void {
@@ -230,15 +245,17 @@ class Logger {
230
245
  }
231
246
  ```
232
247
 
248
+ </TabItem>
249
+ </Tabs>
250
+
233
251
  ### `propertyDeclaration`
234
252
 
235
253
  Whether to enforce type annotations for properties of interfaces and types.
236
254
 
237
255
  Examples of code with `{ "propertyDeclaration": true }`:
238
256
 
239
- <!--tabs-->
240
-
241
- #### ❌ Incorrect
257
+ <Tabs>
258
+ <TabItem value="❌ Incorrect">
242
259
 
243
260
  ```ts option='{ "propertyDeclaration": true }'
244
261
  type Members = {
@@ -247,7 +264,8 @@ type Members = {
247
264
  };
248
265
  ```
249
266
 
250
- #### ✅ Correct
267
+ </TabItem>
268
+ <TabItem value="✅ Correct">
251
269
 
252
270
  ```ts option='{ "propertyDeclaration": true }'
253
271
  type Members = {
@@ -256,15 +274,17 @@ type Members = {
256
274
  };
257
275
  ```
258
276
 
277
+ </TabItem>
278
+ </Tabs>
279
+
259
280
  ### `variableDeclaration`
260
281
 
261
282
  Whether to enforce type annotations for variable declarations, excluding array and object destructuring.
262
283
 
263
284
  Examples of code with `{ "variableDeclaration": true }`:
264
285
 
265
- <!--tabs-->
266
-
267
- #### ❌ Incorrect
286
+ <Tabs>
287
+ <TabItem value="❌ Incorrect">
268
288
 
269
289
  ```ts option='{ "variableDeclaration": true }'
270
290
  const text = 'text';
@@ -272,7 +292,8 @@ let initialText = 'text';
272
292
  let delayedText;
273
293
  ```
274
294
 
275
- #### ✅ Correct
295
+ </TabItem>
296
+ <TabItem value="✅ Correct">
276
297
 
277
298
  ```ts option='{ "variableDeclaration": true }'
278
299
  const text: string = 'text';
@@ -280,21 +301,24 @@ let initialText: string = 'text';
280
301
  let delayedText: string;
281
302
  ```
282
303
 
304
+ </TabItem>
305
+ </Tabs>
306
+
283
307
  ### `variableDeclarationIgnoreFunction`
284
308
 
285
309
  Ignore variable declarations for non-arrow and arrow functions.
286
310
 
287
311
  Examples of code with `{ "variableDeclaration": true, "variableDeclarationIgnoreFunction": true }`:
288
312
 
289
- <!--tabs-->
290
-
291
- #### ❌ Incorrect
313
+ <Tabs>
314
+ <TabItem value="❌ Incorrect">
292
315
 
293
316
  ```ts option='{ "variableDeclaration": true, "variableDeclarationIgnoreFunction": true }'
294
317
  const text = 'text';
295
318
  ```
296
319
 
297
- #### ✅ Correct
320
+ </TabItem>
321
+ <TabItem value="✅ Correct">
298
322
 
299
323
  ```ts option='{ "variableDeclaration": true, "variableDeclarationIgnoreFunction": true }'
300
324
  const a = (): void => {};
@@ -308,6 +332,9 @@ class Foo {
308
332
  }
309
333
  ```
310
334
 
335
+ </TabItem>
336
+ </Tabs>
337
+
311
338
  ## When Not To Use It
312
339
 
313
340
  If you are using stricter TypeScript compiler options, particularly `--noImplicitAny` and/or `--strictPropertyInitialization`, you likely don't need this rule.
@@ -2,6 +2,9 @@
2
2
  description: 'Enforce unbound methods are called with their expected scope.'
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/unbound-method** for documentation.
@@ -13,14 +16,13 @@ Otherwise, passing class methods around as values can remove type safety by fail
13
16
  This rule reports when a class method is referenced in an unbound manner.
14
17
 
15
18
  :::note Tip
16
- If you're working with `jest`, you can use [`eslint-plugin-jest`'s version of this rule](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/unbound-method.md) to lint your test files, which knows when it's ok to pass an unbound method to `expect` calls.
19
+ If you're working with `jest`, you can use [`eslint-plugin-jest`'s version of this rule](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/unbound-method.mdx) to lint your test files, which knows when it's ok to pass an unbound method to `expect` calls.
17
20
  :::
18
21
 
19
22
  ## Examples
20
23
 
21
- <!--tabs-->
22
-
23
- ### ❌ Incorrect
24
+ <Tabs>
25
+ <TabItem value="❌ Incorrect">
24
26
 
25
27
  ```ts
26
28
  class MyClass {
@@ -47,7 +49,8 @@ const arith = {
47
49
  const { double } = arith;
48
50
  ```
49
51
 
50
- ### ✅ Correct
52
+ </TabItem>
53
+ <TabItem value="✅ Correct">
51
54
 
52
55
  ```ts
53
56
  class MyClass {
@@ -77,6 +80,9 @@ const arith = {
77
80
  const { double } = arith;
78
81
  ```
79
82
 
83
+ </TabItem>
84
+ </Tabs>
85
+
80
86
  ## Options
81
87
 
82
88
  ### `ignoreStatic`
@@ -102,4 +108,4 @@ If your project dynamically changes `this` scopes around in a way TypeScript has
102
108
  One likely difficult pattern is if your code intentionally waits to bind methods after use, such as by passing a `scope: this` along with the method.
103
109
  You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
104
110
 
105
- If you're wanting to use `toBeCalled` and similar matches in `jest` tests, you can disable this rule for your test files in favor of [`eslint-plugin-jest`'s version of this rule](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/unbound-method.md).
111
+ If you're wanting to use `toBeCalled` and similar matches in `jest` tests, you can disable this rule for your test files in favor of [`eslint-plugin-jest`'s version of this rule](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/unbound-method.mdx).
@@ -2,6 +2,9 @@
2
2
  description: 'Disallow two overloads that could be unified into one with a union or an optional/rest parameter.'
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/unified-signatures** for documentation.
@@ -14,9 +17,8 @@ This rule reports when function overload signatures can be replaced by a single
14
17
 
15
18
  ## Examples
16
19
 
17
- <!--tabs-->
18
-
19
- ### ❌ Incorrect
20
+ <Tabs>
21
+ <TabItem value="❌ Incorrect">
20
22
 
21
23
  ```ts
22
24
  function x(x: number): void;
@@ -28,7 +30,8 @@ function y(): void;
28
30
  function y(...x: number[]): void;
29
31
  ```
30
32
 
31
- ### ✅ Correct
33
+ </TabItem>
34
+ <TabItem value="✅ Correct">
32
35
 
33
36
  ```ts
34
37
  function x(x: number | string): void;
@@ -45,28 +48,34 @@ function f(...a: number[]): void;
45
48
  function f(...a: string[]): void;
46
49
  ```
47
50
 
51
+ </TabItem>
52
+ </Tabs>
53
+
48
54
  ## Options
49
55
 
50
56
  ### `ignoreDifferentlyNamedParameters`
51
57
 
52
58
  Examples of code for this rule with `ignoreDifferentlyNamedParameters`:
53
59
 
54
- <!--tabs-->
55
-
56
- ### ❌ Incorrect
60
+ <Tabs>
61
+ <TabItem value="❌ Incorrect">
57
62
 
58
63
  ```ts option='{ "ignoreDifferentlyNamedParameters": true }'
59
64
  function f(a: number): void;
60
65
  function f(a: string): void;
61
66
  ```
62
67
 
63
- ### ✅ Correct
68
+ </TabItem>
69
+ <TabItem value="✅ Correct">
64
70
 
65
71
  ```ts option='{ "ignoreDifferentlyNamedParameters": true }'
66
72
  function f(a: number): void;
67
73
  function f(b: string): void;
68
74
  ```
69
75
 
76
+ </TabItem>
77
+ </Tabs>
78
+
70
79
  ## When Not To Use It
71
80
 
72
81
  This is purely a stylistic rule to help with readability of function signature overloads.
@@ -74,4 +83,4 @@ You can turn it off if you don't want to consistently keep them next to each oth
74
83
 
75
84
  ## Related To
76
85
 
77
- - [`adjacent-overload-signatures`](./adjacent-overload-signatures.md)
86
+ - [`adjacent-overload-signatures`](./adjacent-overload-signatures.mdx)
@@ -0,0 +1,84 @@
1
+ ---
2
+ description: 'Enforce typing arguments in `.catch()` callbacks as `unknown`.'
3
+ ---
4
+
5
+ import Tabs from '@theme/Tabs';
6
+ import TabItem from '@theme/TabItem';
7
+
8
+ > 🛑 This file is source code, not the primary documentation location! 🛑
9
+ >
10
+ > See **https://typescript-eslint.io/rules/use-unknown-in-catch-callback-variable** for documentation.
11
+
12
+ This rule enforces that you always use the `unknown` type for the parameter of a `Promise.prototype.catch()` callback.
13
+
14
+ <Tabs>
15
+ <TabItem value="❌ Incorrect">
16
+
17
+ ```ts
18
+ Promise.reject(new Error('I will reject!')).catch(err => {
19
+ console.log(err);
20
+ });
21
+
22
+ Promise.reject(new Error('I will reject!')).catch((err: any) => {
23
+ console.log(err);
24
+ });
25
+
26
+ Promise.reject(new Error('I will reject!')).catch((err: Error) => {
27
+ console.log(err);
28
+ });
29
+ ```
30
+
31
+ </TabItem>
32
+ <TabItem value="✅ Correct">
33
+
34
+ ```ts
35
+ Promise.reject(new Error('I will reject!')).catch((err: unknown) => {
36
+ console.log(err);
37
+ });
38
+ ```
39
+
40
+ </TabItem>
41
+ </Tabs>
42
+
43
+ The reason for this rule is to enable programmers to impose constraints on `Promise` error handling analogously to what TypeScript provides for ordinary exception handling.
44
+
45
+ For ordinary exceptions, TypeScript treats the `catch` variable as `any` by default. However, `unknown` would be a more accurate type, so TypeScript [introduced the `useUnknownInCatchVariables` compiler option](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-4.html#defaulting-to-the-unknown-type-in-catch-variables---useunknownincatchvariables) to treat the `catch` variable as `unknown` instead.
46
+
47
+ ```ts
48
+ try {
49
+ throw x;
50
+ } catch (err) {
51
+ // err has type 'any' with useUnknownInCatchVariables: false
52
+ // err has type 'unknown' with useUnknownInCatchVariables: true
53
+ }
54
+ ```
55
+
56
+ The Promise analog of the `try-catch` block, [`Promise.prototype.catch()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch), is not affected by the `useUnknownInCatchVariables` compiler option, and its "`catch` variable" will always have the type `any`.
57
+
58
+ ```ts
59
+ Promise.reject(x).catch(err => {
60
+ // err has type 'any' regardless of `useUnknownInCatchVariables`
61
+ });
62
+ ```
63
+
64
+ However, you can still provide an explicit type annotation, which lets you achieve the same effect as the `useUnknownInCatchVariables` option does for synchronous `catch` variables.
65
+
66
+ ```ts
67
+ Promise.reject(x).catch((err: unknown) => {
68
+ // err has type 'unknown'
69
+ });
70
+ ```
71
+
72
+ :::info
73
+ There is actually a way to have the `catch()` callback variable use the `unknown` type _without_ an explicit type annotation at the call sites, but it has the drawback that it involves overriding global type declarations.
74
+ For example, the library [better-TypeScript-lib](https://github.com/uhyo/better-typescript-lib) sets this up globally for your project (see [the relevant lines in the better-TypeScript-lib source code](https://github.com/uhyo/better-typescript-lib/blob/c294e177d1cc2b1d1803febf8192a4c83a1fe028/lib/lib.es5.d.ts#L635) for details on how).
75
+
76
+ For further reading on this, you may also want to look into
77
+ [the discussion in the proposal for this rule](https://github.com/typescript-eslint/typescript-eslint/issues/7526#issuecomment-1690600813) and [this TypeScript issue on typing catch callback variables as unknown](https://github.com/microsoft/TypeScript/issues/45602).
78
+ :::
79
+
80
+ ## When Not To Use It
81
+
82
+ If your codebase is not yet able to enable `useUnknownInCatchVariables`, it likely would be similarly difficult to enable this rule.
83
+
84
+ If you have modified the global type declarations in order to make `catch()` callbacks use the `unknown` type without an explicit type annotation, you do not need this rule.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "7.2.1-alpha.1",
3
+ "version": "7.2.1-alpha.3",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -28,7 +28,7 @@
28
28
  }
29
29
  },
30
30
  "engines": {
31
- "node": "^16.0.0 || >=18.0.0"
31
+ "node": "^18.18.0 || >=20.0.0"
32
32
  },
33
33
  "repository": {
34
34
  "type": "git",
@@ -61,10 +61,10 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "@eslint-community/regexpp": "^4.5.1",
64
- "@typescript-eslint/scope-manager": "7.2.1-alpha.1",
65
- "@typescript-eslint/type-utils": "7.2.1-alpha.1",
66
- "@typescript-eslint/utils": "7.2.1-alpha.1",
67
- "@typescript-eslint/visitor-keys": "7.2.1-alpha.1",
64
+ "@typescript-eslint/scope-manager": "7.2.1-alpha.3",
65
+ "@typescript-eslint/type-utils": "7.2.1-alpha.3",
66
+ "@typescript-eslint/utils": "7.2.1-alpha.3",
67
+ "@typescript-eslint/visitor-keys": "7.2.1-alpha.3",
68
68
  "debug": "^4.3.4",
69
69
  "graphemer": "^1.4.0",
70
70
  "ignore": "^5.2.4",
@@ -76,8 +76,8 @@
76
76
  "@types/debug": "*",
77
77
  "@types/marked": "*",
78
78
  "@types/natural-compare": "*",
79
- "@typescript-eslint/rule-schema-to-typescript-types": "7.2.1-alpha.1",
80
- "@typescript-eslint/rule-tester": "7.2.1-alpha.1",
79
+ "@typescript-eslint/rule-schema-to-typescript-types": "7.2.1-alpha.3",
80
+ "@typescript-eslint/rule-tester": "7.2.1-alpha.3",
81
81
  "ajv": "^6.12.6",
82
82
  "chalk": "^5.3.0",
83
83
  "cross-env": "^7.0.3",