@typescript-eslint/eslint-plugin 8.9.1-alpha.5 → 8.9.1-alpha.7
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/rules/class-literal-property-style.js +1 -0
- package/dist/rules/class-literal-property-style.js.map +1 -1
- package/dist/rules/class-methods-use-this.js +3 -3
- package/dist/rules/class-methods-use-this.js.map +1 -1
- package/dist/rules/consistent-generic-constructors.js +1 -0
- package/dist/rules/consistent-generic-constructors.js.map +1 -1
- package/dist/rules/consistent-indexed-object-style.js +1 -0
- package/dist/rules/consistent-indexed-object-style.js.map +1 -1
- package/dist/rules/consistent-type-definitions.js +1 -0
- package/dist/rules/consistent-type-definitions.js.map +1 -1
- package/dist/rules/explicit-member-accessibility.js +5 -1
- package/dist/rules/explicit-member-accessibility.js.map +1 -1
- package/dist/rules/no-invalid-void-type.js +7 -3
- package/dist/rules/no-invalid-void-type.js.map +1 -1
- package/dist/rules/no-misused-promises.js +7 -1
- package/dist/rules/no-misused-promises.js.map +1 -1
- package/dist/rules/no-restricted-imports.js +1 -1
- package/dist/rules/no-restricted-imports.js.map +1 -1
- package/dist/rules/no-restricted-types.js +5 -4
- package/dist/rules/no-restricted-types.js.map +1 -1
- package/dist/rules/no-use-before-define.js +4 -1
- package/dist/rules/no-use-before-define.js.map +1 -1
- package/dist/rules/prefer-destructuring.js +2 -0
- package/dist/rules/prefer-destructuring.js.map +1 -1
- package/dist/rules/prefer-nullish-coalescing.js +18 -4
- package/dist/rules/prefer-nullish-coalescing.js.map +1 -1
- package/dist/rules/sort-type-constituents.js +3 -3
- package/dist/rules/sort-type-constituents.js.map +1 -1
- package/dist/rules/strict-boolean-expressions.js +5 -4
- package/dist/rules/strict-boolean-expressions.js.map +1 -1
- package/docs/rules/ban-ts-comment.mdx +4 -0
- package/docs/rules/class-methods-use-this.mdx +4 -1
- package/docs/rules/consistent-generic-constructors.mdx +6 -4
- package/docs/rules/consistent-indexed-object-style.mdx +6 -4
- package/docs/rules/consistent-type-assertions.mdx +4 -2
- package/docs/rules/consistent-type-definitions.mdx +8 -4
- package/docs/rules/consistent-type-exports.mdx +2 -1
- package/docs/rules/consistent-type-imports.mdx +7 -4
- package/docs/rules/dot-notation.mdx +5 -3
- package/docs/rules/explicit-function-return-type.mdx +16 -0
- package/docs/rules/explicit-member-accessibility.mdx +7 -2
- package/docs/rules/explicit-module-boundary-types.mdx +22 -12
- package/docs/rules/max-params.mdx +1 -1
- package/docs/rules/method-signature-style.mdx +4 -2
- package/docs/rules/no-base-to-string.mdx +5 -3
- package/docs/rules/no-confusing-void-expression.mdx +4 -0
- package/docs/rules/no-duplicate-type-constituents.mdx +4 -0
- package/docs/rules/no-empty-interface.mdx +3 -1
- package/docs/rules/no-empty-object-type.mdx +8 -3
- package/docs/rules/no-explicit-any.mdx +3 -1
- package/docs/rules/no-extraneous-class.mdx +4 -4
- package/docs/rules/no-floating-promises.mdx +12 -6
- package/docs/rules/no-inferrable-types.mdx +2 -2
- package/docs/rules/no-invalid-void-type.mdx +4 -3
- package/docs/rules/no-magic-numbers.mdx +8 -0
- package/docs/rules/no-meaningless-void-operator.mdx +1 -1
- package/docs/rules/no-misused-promises.mdx +11 -1
- package/docs/rules/no-namespace.mdx +4 -0
- package/docs/rules/no-redeclare.mdx +3 -1
- package/docs/rules/no-require-imports.mdx +6 -2
- package/docs/rules/no-restricted-imports.mdx +4 -1
- package/docs/rules/no-restricted-types.mdx +1 -1
- package/docs/rules/no-shadow.mdx +4 -2
- package/docs/rules/no-this-alias.mdx +4 -0
- package/docs/rules/no-type-alias.mdx +8 -8
- package/docs/rules/no-unnecessary-boolean-literal-compare.mdx +4 -0
- package/docs/rules/no-unnecessary-condition.mdx +6 -0
- package/docs/rules/no-unnecessary-type-assertion.mdx +2 -0
- package/docs/rules/no-use-before-define.mdx +3 -3
- package/docs/rules/no-var-requires.mdx +2 -0
- package/docs/rules/parameter-properties.mdx +6 -2
- package/docs/rules/prefer-destructuring.mdx +1 -1
- package/docs/rules/prefer-literal-enum-member.mdx +1 -1
- package/docs/rules/prefer-nullish-coalescing.mdx +6 -4
- package/docs/rules/prefer-optional-chain.mdx +37 -28
- package/docs/rules/prefer-readonly-parameter-types.mdx +8 -4
- package/docs/rules/prefer-readonly.mdx +1 -1
- package/docs/rules/prefer-string-starts-ends-with.mdx +2 -0
- package/docs/rules/promise-function-async.mdx +8 -9
- package/docs/rules/require-array-sort-compare.mdx +2 -0
- package/docs/rules/restrict-plus-operands.mdx +12 -0
- package/docs/rules/restrict-template-expressions.mdx +9 -7
- package/docs/rules/return-await.mdx +4 -0
- package/docs/rules/sort-type-constituents.mdx +5 -3
- package/docs/rules/strict-boolean-expressions.mdx +22 -12
- package/docs/rules/switch-exhaustiveness-check.mdx +6 -2
- package/docs/rules/triple-slash-reference.mdx +6 -0
- package/docs/rules/typedef.mdx +8 -8
- package/docs/rules/unbound-method.mdx +2 -0
- package/docs/rules/unified-signatures.mdx +2 -0
- package/package.json +7 -7
@@ -114,7 +114,7 @@ and simplified types (primitives, tuples, unions, intersections, etc).
|
|
114
114
|
|
115
115
|
### `allowAliases`
|
116
116
|
|
117
|
-
|
117
|
+
{/* insert option description */}
|
118
118
|
|
119
119
|
The setting accepts the following values:
|
120
120
|
|
@@ -268,7 +268,7 @@ type Foo = Bar & Baz;
|
|
268
268
|
|
269
269
|
### `allowCallbacks`
|
270
270
|
|
271
|
-
|
271
|
+
{/* insert option description */}
|
272
272
|
|
273
273
|
The setting accepts the following values:
|
274
274
|
|
@@ -290,7 +290,7 @@ type Foo = (name: string, age: number) => string & Person;
|
|
290
290
|
|
291
291
|
### `allowConditionalTypes`
|
292
292
|
|
293
|
-
|
293
|
+
{/* insert option description */}
|
294
294
|
|
295
295
|
Examples of **correct** code for the `{ "allowConditionalTypes": "always" }` option:
|
296
296
|
|
@@ -300,7 +300,7 @@ type Foo<T> = T extends number ? number : null;
|
|
300
300
|
|
301
301
|
### `allowConstructors`
|
302
302
|
|
303
|
-
|
303
|
+
{/* insert option description */}
|
304
304
|
|
305
305
|
The setting accepts the following values:
|
306
306
|
|
@@ -314,7 +314,7 @@ type Foo = new () => void;
|
|
314
314
|
|
315
315
|
### `allowLiterals`
|
316
316
|
|
317
|
-
|
317
|
+
{/* insert option description */}
|
318
318
|
|
319
319
|
The setting accepts the following options:
|
320
320
|
|
@@ -421,7 +421,7 @@ type Foo = { name: string } & { age: number };
|
|
421
421
|
|
422
422
|
### `allowMappedTypes`
|
423
423
|
|
424
|
-
|
424
|
+
{/* insert option description */}
|
425
425
|
|
426
426
|
The setting accepts the following values:
|
427
427
|
|
@@ -524,7 +524,7 @@ type Foo<T, U> = { [P in keyof T]?: T[P] } & { [P in keyof U]?: U[P] };
|
|
524
524
|
|
525
525
|
### `allowTupleTypes`
|
526
526
|
|
527
|
-
|
527
|
+
{/* insert option description */}
|
528
528
|
|
529
529
|
The setting accepts the following options:
|
530
530
|
|
@@ -599,7 +599,7 @@ type Foo = [string] | [number];
|
|
599
599
|
|
600
600
|
### `allowGenerics`
|
601
601
|
|
602
|
-
|
602
|
+
{/* insert option description */}
|
603
603
|
|
604
604
|
The setting accepts the following options:
|
605
605
|
|
@@ -61,6 +61,8 @@ are **not** checked by default.
|
|
61
61
|
|
62
62
|
### `allowComparingNullableBooleansToTrue`
|
63
63
|
|
64
|
+
{/* insert option description */}
|
65
|
+
|
64
66
|
Examples of code for this rule with `{ allowComparingNullableBooleansToTrue: false }`:
|
65
67
|
|
66
68
|
<Tabs>
|
@@ -94,6 +96,8 @@ if (!someNullCondition) {
|
|
94
96
|
|
95
97
|
### `allowComparingNullableBooleansToFalse`
|
96
98
|
|
99
|
+
{/* insert option description */}
|
100
|
+
|
97
101
|
Examples of code for this rule with `{ allowComparingNullableBooleansToFalse: false }`:
|
98
102
|
|
99
103
|
<Tabs>
|
@@ -82,6 +82,8 @@ function bar(arg?: string | null) {
|
|
82
82
|
|
83
83
|
### `allowConstantLoopConditions`
|
84
84
|
|
85
|
+
{/* insert option description */}
|
86
|
+
|
85
87
|
Example of correct code for `{ allowConstantLoopConditions: true }`:
|
86
88
|
|
87
89
|
```ts option='{ "allowConstantLoopConditions": true }' showPlaygroundButton
|
@@ -92,6 +94,8 @@ do {} while (true);
|
|
92
94
|
|
93
95
|
### `checkTypePredicates`
|
94
96
|
|
97
|
+
{/* insert option description */}
|
98
|
+
|
95
99
|
Example of additional incorrect code with `{ checkTypePredicates: true }`:
|
96
100
|
|
97
101
|
```ts option='{ "checkTypePredicates": true }' showPlaygroundButton
|
@@ -132,6 +136,8 @@ However, in some contexts, it may be more appropriate to keep this option disabl
|
|
132
136
|
|
133
137
|
### `allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing`
|
134
138
|
|
139
|
+
{/* insert option description */}
|
140
|
+
|
135
141
|
:::danger Deprecated
|
136
142
|
This option will be removed in the next major version of typescript-eslint.
|
137
143
|
:::
|
@@ -75,6 +75,8 @@ function foo(x: number | undefined): number {
|
|
75
75
|
|
76
76
|
### `typesToIgnore`
|
77
77
|
|
78
|
+
{/* insert option description */}
|
79
|
+
|
78
80
|
With `@typescript-eslint/no-unnecessary-type-assertion: ["error", { typesToIgnore: ['Foo'] }]`, the following is **correct** code:
|
79
81
|
|
80
82
|
```ts option='{ "typesToIgnore": ["Foo"] }' showPlaygroundButton
|
@@ -33,7 +33,7 @@ const defaultOptions: Options = {
|
|
33
33
|
|
34
34
|
### `enums`
|
35
35
|
|
36
|
-
|
36
|
+
{/* insert option description */}
|
37
37
|
|
38
38
|
If this is `true`, this rule warns every reference to a enum before the enum declaration.
|
39
39
|
If this is `false`, this rule will ignore references to enums, when the reference is in a child scope.
|
@@ -69,7 +69,7 @@ enum Foo {
|
|
69
69
|
|
70
70
|
### `typedefs`
|
71
71
|
|
72
|
-
|
72
|
+
{/* insert option description */}
|
73
73
|
|
74
74
|
If this is `true`, this rule warns every reference to a type before the type declaration.
|
75
75
|
If this is `false`, this rule will ignore references to types.
|
@@ -83,7 +83,7 @@ type StringOrNumber = string | number;
|
|
83
83
|
|
84
84
|
### `ignoreTypeReferences`
|
85
85
|
|
86
|
-
|
86
|
+
{/* insert option description */}
|
87
87
|
|
88
88
|
If this is `true`, this rule ignores all type references.
|
89
89
|
If this is `false`, this will check all type references.
|
@@ -44,6 +44,8 @@ import foo from 'foo';
|
|
44
44
|
|
45
45
|
### `allow`
|
46
46
|
|
47
|
+
{/* insert option description */}
|
48
|
+
|
47
49
|
A array of strings. These strings will be compiled into regular expressions with the `u` flag and be used to test against the imported path. A common use case is to allow importing `package.json`. This is because `package.json` commonly lives outside of the TS root directory, so statically importing it would lead to root directory conflicts, especially with `resolveJsonModule` enabled. You can also use it to allow importing any JSON if your environment doesn't support JSON modules, or use it for other cases where `import` statements cannot work.
|
48
50
|
|
49
51
|
With `{allow: ['/package\\.json$']}`:
|
@@ -24,6 +24,8 @@ It may take an options object containing either or both of:
|
|
24
24
|
|
25
25
|
### `allow`
|
26
26
|
|
27
|
+
{/* insert option description */}
|
28
|
+
|
27
29
|
If you would like to ignore certain kinds of properties then you may pass an object containing `"allow"` as an array of any of the following options:
|
28
30
|
|
29
31
|
- `allow`, an array containing one or more of the allowed modifiers. Valid values are:
|
@@ -50,8 +52,10 @@ For example, to ignore `public` properties:
|
|
50
52
|
|
51
53
|
### `prefer`
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
+
{/* insert option description */}
|
56
|
+
|
57
|
+
By default, the rule prefers class properties.
|
58
|
+
You can switch it to instead preferring parameter properties with (`"parameter-property"`).
|
55
59
|
|
56
60
|
In `"parameter-property"` mode, the rule will issue a report when:
|
57
61
|
|
@@ -80,7 +80,7 @@ const defaultOptions: Options = [
|
|
80
80
|
|
81
81
|
### `enforceForDeclarationWithTypeAnnotation`
|
82
82
|
|
83
|
-
|
83
|
+
{/* insert option description */}
|
84
84
|
|
85
85
|
Examples with `{ enforceForDeclarationWithTypeAnnotation: true }`:
|
86
86
|
|
@@ -25,7 +25,7 @@ This rule will not work as expected if [`strictNullChecks`](https://www.typescri
|
|
25
25
|
|
26
26
|
### `ignoreTernaryTests`
|
27
27
|
|
28
|
-
|
28
|
+
{/* insert option description */}
|
29
29
|
|
30
30
|
Incorrect code for `ignoreTernaryTests: false`, and correct code for `ignoreTernaryTests: true`:
|
31
31
|
|
@@ -65,7 +65,7 @@ foo ?? 'a string';
|
|
65
65
|
|
66
66
|
### `ignoreConditionalTests`
|
67
67
|
|
68
|
-
|
68
|
+
{/* insert option description */}
|
69
69
|
|
70
70
|
Generally expressions within conditional tests intentionally use the falsy fallthrough behavior of the logical or operator, meaning that fixing the operator to the nullish coalesce operator could cause bugs.
|
71
71
|
|
@@ -107,7 +107,7 @@ a ?? b ? true : false;
|
|
107
107
|
|
108
108
|
### `ignoreMixedLogicalExpressions`
|
109
109
|
|
110
|
-
|
110
|
+
{/* insert option description */}
|
111
111
|
|
112
112
|
Generally expressions within mixed logical expressions intentionally use the falsy fallthrough behavior of the logical or operator, meaning that fixing the operator to the nullish coalesce operator could cause bugs.
|
113
113
|
|
@@ -147,7 +147,7 @@ a ?? (b && c && d);
|
|
147
147
|
|
148
148
|
### `ignorePrimitives`
|
149
149
|
|
150
|
-
|
150
|
+
{/* insert option description */}
|
151
151
|
|
152
152
|
If you would like to ignore expressions containing operands of certain primitive types that can be falsy then you may pass an object containing a boolean value for each primitive:
|
153
153
|
|
@@ -174,6 +174,8 @@ Also, if you would like to ignore all primitives types, you can set `ignorePrimi
|
|
174
174
|
|
175
175
|
### `allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing`
|
176
176
|
|
177
|
+
{/* insert option description */}
|
178
|
+
|
177
179
|
:::danger Deprecated
|
178
180
|
|
179
181
|
> This option will be removed in the next major version of typescript-eslint.
|
@@ -68,6 +68,8 @@ Specifically the argument of the not operator (`!loose`) or a bare value in a lo
|
|
68
68
|
|
69
69
|
### `allowPotentiallyUnsafeFixesThatModifyTheReturnTypeIKnowWhatImDoing`
|
70
70
|
|
71
|
+
{/* insert option description */}
|
72
|
+
|
71
73
|
When this option is `true`, the rule will provide an auto-fixer for cases where the return type of the expression would change. For example for the expression `!foo || foo.bar` the return type of the expression is `true | T`, however for the equivalent optional chain `foo?.bar` the return type of the expression is `undefined | T`. Thus changing the code from a logical expression to an optional chain expression has altered the type of the expression.
|
72
74
|
|
73
75
|
In some cases this distinction _may_ matter - which is why these fixers are considered unsafe - they may break the build! For example in the following code:
|
@@ -89,11 +91,12 @@ When this option is `false` unsafe cases will have suggestion fixers provided in
|
|
89
91
|
|
90
92
|
### `checkAny`
|
91
93
|
|
92
|
-
|
94
|
+
{/* insert option description */}
|
93
95
|
|
94
|
-
|
96
|
+
Examples of code for this rule with `{ checkAny: false }`:
|
95
97
|
|
96
|
-
<
|
98
|
+
<Tabs>
|
99
|
+
<TabItem value="❌ Incorrect">
|
97
100
|
|
98
101
|
```ts option='{ "checkAny": true }'
|
99
102
|
declare const thing: any;
|
@@ -102,7 +105,7 @@ thing && thing.toString();
|
|
102
105
|
```
|
103
106
|
|
104
107
|
</TabItem>
|
105
|
-
<TabItem value="✅ Correct
|
108
|
+
<TabItem value="✅ Correct">
|
106
109
|
|
107
110
|
```ts option='{ "checkAny": false }'
|
108
111
|
declare const thing: any;
|
@@ -115,11 +118,12 @@ thing && thing.toString();
|
|
115
118
|
|
116
119
|
### `checkUnknown`
|
117
120
|
|
118
|
-
|
121
|
+
{/* insert option description */}
|
119
122
|
|
120
|
-
|
123
|
+
Examples of code for this rule with `{ checkUnknown: false }`:
|
121
124
|
|
122
|
-
<
|
125
|
+
<Tabs>
|
126
|
+
<TabItem value="❌ Incorrect">
|
123
127
|
|
124
128
|
```ts option='{ "checkUnknown": true }'
|
125
129
|
declare const thing: unknown;
|
@@ -128,7 +132,7 @@ thing && thing.toString();
|
|
128
132
|
```
|
129
133
|
|
130
134
|
</TabItem>
|
131
|
-
<TabItem value="✅ Correct
|
135
|
+
<TabItem value="✅ Correct">
|
132
136
|
|
133
137
|
```ts option='{ "checkUnknown": false }'
|
134
138
|
declare const thing: unknown;
|
@@ -141,11 +145,12 @@ thing && thing.toString();
|
|
141
145
|
|
142
146
|
### `checkString`
|
143
147
|
|
144
|
-
|
148
|
+
{/* insert option description */}
|
145
149
|
|
146
|
-
|
150
|
+
Examples of code for this rule with `{ checkString: false }`:
|
147
151
|
|
148
|
-
<
|
152
|
+
<Tabs>
|
153
|
+
<TabItem value="❌ Incorrect">
|
149
154
|
|
150
155
|
```ts option='{ "checkString": true }'
|
151
156
|
declare const thing: string;
|
@@ -154,7 +159,7 @@ thing && thing.toString();
|
|
154
159
|
```
|
155
160
|
|
156
161
|
</TabItem>
|
157
|
-
<TabItem value="✅ Correct
|
162
|
+
<TabItem value="✅ Correct">
|
158
163
|
|
159
164
|
```ts option='{ "checkString": false }'
|
160
165
|
declare const thing: string;
|
@@ -167,11 +172,12 @@ thing && thing.toString();
|
|
167
172
|
|
168
173
|
### `checkNumber`
|
169
174
|
|
170
|
-
|
175
|
+
{/* insert option description */}
|
171
176
|
|
172
|
-
|
177
|
+
Examples of code for this rule with `{ checkNumber: false }`:
|
173
178
|
|
174
|
-
<
|
179
|
+
<Tabs>
|
180
|
+
<TabItem value="❌ Incorrect">
|
175
181
|
|
176
182
|
```ts option='{ "checkNumber": true }'
|
177
183
|
declare const thing: number;
|
@@ -180,7 +186,7 @@ thing && thing.toString();
|
|
180
186
|
```
|
181
187
|
|
182
188
|
</TabItem>
|
183
|
-
<TabItem value="✅ Correct
|
189
|
+
<TabItem value="✅ Correct">
|
184
190
|
|
185
191
|
```ts option='{ "checkNumber": false }'
|
186
192
|
declare const thing: number;
|
@@ -193,7 +199,7 @@ thing && thing.toString();
|
|
193
199
|
|
194
200
|
### `checkBoolean`
|
195
201
|
|
196
|
-
|
202
|
+
{/* insert option description */}
|
197
203
|
|
198
204
|
:::note
|
199
205
|
|
@@ -209,9 +215,10 @@ The boolean expression narrows out the non-nullish falsy cases - so converting t
|
|
209
215
|
|
210
216
|
:::
|
211
217
|
|
212
|
-
|
218
|
+
Examples of code for this rule with `{ checkBoolean: false }`:
|
213
219
|
|
214
|
-
<
|
220
|
+
<Tabs>
|
221
|
+
<TabItem value="❌ Incorrect">
|
215
222
|
|
216
223
|
```ts option='{ "checkBoolean": true }'
|
217
224
|
declare const thing: true;
|
@@ -220,7 +227,7 @@ thing && thing.toString();
|
|
220
227
|
```
|
221
228
|
|
222
229
|
</TabItem>
|
223
|
-
<TabItem value="✅ Correct
|
230
|
+
<TabItem value="✅ Correct">
|
224
231
|
|
225
232
|
```ts option='{ "checkBoolean": false }'
|
226
233
|
declare const thing: true;
|
@@ -233,11 +240,12 @@ thing && thing.toString();
|
|
233
240
|
|
234
241
|
### `checkBigInt`
|
235
242
|
|
236
|
-
|
243
|
+
{/* insert option description */}
|
237
244
|
|
238
|
-
|
245
|
+
Examples of code for this rule with `{ checkBigInt: false }`:
|
239
246
|
|
240
|
-
<
|
247
|
+
<Tabs>
|
248
|
+
<TabItem value="❌ Incorrect">
|
241
249
|
|
242
250
|
```ts option='{ "checkBigInt": true }'
|
243
251
|
declare const thing: bigint;
|
@@ -246,7 +254,7 @@ thing && thing.toString();
|
|
246
254
|
```
|
247
255
|
|
248
256
|
</TabItem>
|
249
|
-
<TabItem value="✅ Correct
|
257
|
+
<TabItem value="✅ Correct">
|
250
258
|
|
251
259
|
```ts option='{ "checkBigInt": false }'
|
252
260
|
declare const thing: bigint;
|
@@ -259,11 +267,12 @@ thing && thing.toString();
|
|
259
267
|
|
260
268
|
### `requireNullish`
|
261
269
|
|
262
|
-
|
270
|
+
{/* insert option description */}
|
263
271
|
|
264
|
-
|
272
|
+
Examples of code for this rule with `{ requireNullish: false }`:
|
265
273
|
|
266
|
-
<
|
274
|
+
<Tabs>
|
275
|
+
<TabItem value="❌ Incorrect">
|
267
276
|
|
268
277
|
```ts option='{ "requireNullish": true }'
|
269
278
|
declare const thing1: string | null;
|
@@ -271,7 +280,7 @@ thing1 && thing1.toString();
|
|
271
280
|
```
|
272
281
|
|
273
282
|
</TabItem>
|
274
|
-
<TabItem value="✅ Correct
|
283
|
+
<TabItem value="✅ Correct">
|
275
284
|
|
276
285
|
```ts option='{ "requireNullish": true }'
|
277
286
|
declare const thing1: string | null;
|
@@ -140,7 +140,8 @@ interface Foo {
|
|
140
140
|
|
141
141
|
### `allow`
|
142
142
|
|
143
|
-
|
143
|
+
{/* insert option description */}
|
144
|
+
|
144
145
|
Some complex types cannot easily be made readonly, for example the `HTMLElement` type or the `JQueryStatic` type from `@types/jquery`. This option allows you to globally disable reporting of such types.
|
145
146
|
|
146
147
|
This option takes the shared [`TypeOrValueSpecifier` format](/packages/type-utils/type-or-value-specifier).
|
@@ -251,7 +252,8 @@ function fn(arg: Foo) {}
|
|
251
252
|
|
252
253
|
### `checkParameterProperties`
|
253
254
|
|
254
|
-
|
255
|
+
{/* insert option description */}
|
256
|
+
|
255
257
|
Because parameter properties create properties on the class, it may be undesirable to force them to be readonly.
|
256
258
|
|
257
259
|
Examples of code for this rule with `{checkParameterProperties: true}`:
|
@@ -290,7 +292,8 @@ class Foo {
|
|
290
292
|
|
291
293
|
### `ignoreInferredTypes`
|
292
294
|
|
293
|
-
|
295
|
+
{/* insert option description */}
|
296
|
+
|
294
297
|
This may be desirable in cases where an external dependency specifies a callback with mutable parameters, and manually annotating the callback's parameters is undesirable.
|
295
298
|
|
296
299
|
Examples of code for this rule with `{ignoreInferredTypes: true}`:
|
@@ -348,7 +351,8 @@ export const acceptsCallback: AcceptsCallback;
|
|
348
351
|
|
349
352
|
### `treatMethodsAsReadonly`
|
350
353
|
|
351
|
-
|
354
|
+
{/* insert option description */}
|
355
|
+
|
352
356
|
This may be desirable when you are never reassigning methods.
|
353
357
|
|
354
358
|
Examples of code for this rule with `{treatMethodsAsReadonly: false}`:
|
@@ -62,6 +62,8 @@ foo.endsWith('bar');
|
|
62
62
|
|
63
63
|
### `allowSingleElementEquality`
|
64
64
|
|
65
|
+
{/* insert option description */}
|
66
|
+
|
65
67
|
If switched to `'always'`, the rule will allow equality checks against the first or last character in a string.
|
66
68
|
This can be preferable in projects that don't deal with special character encodings and prefer a more succinct style.
|
67
69
|
|
@@ -68,7 +68,8 @@ async function functionReturnsUnionWithPromiseImplicitly(p: boolean) {
|
|
68
68
|
|
69
69
|
### `allowAny`
|
70
70
|
|
71
|
-
|
71
|
+
{/* insert option description */}
|
72
|
+
|
72
73
|
If you want additional safety, consider turning this option off, as it makes the rule less able to catch incorrect Promise behaviors.
|
73
74
|
|
74
75
|
Examples of code with `{ "allowAny": false }`:
|
@@ -92,6 +93,8 @@ const returnsAny = async () => ({}) as any;
|
|
92
93
|
|
93
94
|
### `allowedPromiseNames`
|
94
95
|
|
96
|
+
{/* insert option description */}
|
97
|
+
|
95
98
|
For projects that use constructs other than the global built-in `Promise` for asynchronous code.
|
96
99
|
This option allows specifying string names of classes or interfaces that cause a function to be checked as well.
|
97
100
|
|
@@ -120,23 +123,19 @@ const returnsBluebird = async () => new Bluebird(() => {});
|
|
120
123
|
|
121
124
|
### `checkArrowFunctions`
|
122
125
|
|
123
|
-
|
124
|
-
`true` by default, but can be set to `false` to ignore them.
|
126
|
+
{/* insert option description */}
|
125
127
|
|
126
128
|
### `checkFunctionDeclarations`
|
127
129
|
|
128
|
-
|
129
|
-
`true` by default, but can be set to `false` to ignore them.
|
130
|
+
{/* insert option description */}
|
130
131
|
|
131
132
|
### `checkFunctionExpressions`
|
132
133
|
|
133
|
-
|
134
|
-
`true` by default, but can be set to `false` to ignore them.
|
134
|
+
{/* insert option description */}
|
135
135
|
|
136
136
|
### `checkMethodDeclarations`
|
137
137
|
|
138
|
-
|
139
|
-
`true` by default, but can be set to `false` to ignore them.
|
138
|
+
{/* insert option description */}
|
140
139
|
|
141
140
|
## When Not To Use It
|
142
141
|
|
@@ -74,6 +74,8 @@ Safer alternatives to using the `allow*` options include:
|
|
74
74
|
|
75
75
|
### `allowAny`
|
76
76
|
|
77
|
+
{/* insert option description */}
|
78
|
+
|
77
79
|
Examples of code for this rule with `{ allowAny: true }`:
|
78
80
|
|
79
81
|
<Tabs>
|
@@ -97,6 +99,8 @@ let fn = (a: string, b: any) => a + b;
|
|
97
99
|
|
98
100
|
### `allowBoolean`
|
99
101
|
|
102
|
+
{/* insert option description */}
|
103
|
+
|
100
104
|
Examples of code for this rule with `{ allowBoolean: true }`:
|
101
105
|
|
102
106
|
<Tabs>
|
@@ -120,6 +124,8 @@ let fn = (a: string, b: boolean) => a + b;
|
|
120
124
|
|
121
125
|
### `allowNullish`
|
122
126
|
|
127
|
+
{/* insert option description */}
|
128
|
+
|
123
129
|
Examples of code for this rule with `{ allowNullish: true }`:
|
124
130
|
|
125
131
|
<Tabs>
|
@@ -147,6 +153,8 @@ let fn = (a: string, b: null) => a + b;
|
|
147
153
|
|
148
154
|
### `allowNumberAndString`
|
149
155
|
|
156
|
+
{/* insert option description */}
|
157
|
+
|
150
158
|
Examples of code for this rule with `{ allowNumberAndString: true }`:
|
151
159
|
|
152
160
|
<Tabs>
|
@@ -170,6 +178,8 @@ let fn = (a: number, b: number | string) => a + b;
|
|
170
178
|
|
171
179
|
### `allowRegExp`
|
172
180
|
|
181
|
+
{/* insert option description */}
|
182
|
+
|
173
183
|
Examples of code for this rule with `{ allowRegExp: true }`:
|
174
184
|
|
175
185
|
<Tabs>
|
@@ -191,6 +201,8 @@ let fn = (a: string, b: RegExp) => a + b;
|
|
191
201
|
|
192
202
|
### `skipCompoundAssignments`
|
193
203
|
|
204
|
+
{/* insert option description */}
|
205
|
+
|
194
206
|
Examples of code for this rule with `{ skipCompoundAssignments: false }`:
|
195
207
|
|
196
208
|
<Tabs>
|