@@ -71,16 +71,9 @@ The rule accepts an options object with the following properties:
71
71
``` ts
72
72
type Options = {
73
73
/**
74
- * If true, type annotations are also allowed on the variable of a function expression
75
- * rather than on the function arguments/return value directly.
76
- */
77
- allowTypedFunctionExpressions? : boolean ;
78
- /**
79
- * If true, functions immediately returning another function expression will not
80
- * require an explicit return value annotation.
81
- * You must still type the parameters of the function.
74
+ * If true, the rule will not report for arguments that are explicitly typed as `any`
82
75
*/
83
- allowHigherOrderFunctions ? : boolean ;
76
+ allowArgumentsExplicitlyTypedAsAny ? : boolean ;
84
77
/**
85
78
* If true, body-less arrow functions that return an `as const` type assertion will not
86
79
* require an explicit return value annotation.
@@ -92,16 +85,24 @@ type Options = {
92
85
*/
93
86
allowedNames? : string [];
94
87
/**
95
- * If true, track references to exported variables as well as direct exports.
88
+ * If true, functions immediately returning another function expression will not
89
+ * require an explicit return value annotation.
90
+ * You must still type the parameters of the function.
91
+ */
92
+ allowHigherOrderFunctions? : boolean ;
93
+ /**
94
+ * If true, type annotations are also allowed on the variable of a function expression
95
+ * rather than on the function arguments/return value directly.
96
96
*/
97
- shouldTrackReferences ? : boolean ;
97
+ allowTypedFunctionExpressions ? : boolean ;
98
98
};
99
99
100
100
const defaults = {
101
- allowTypedFunctionExpressions: true ,
102
- allowHigherOrderFunctions : true ,
101
+ allowArgumentsExplicitlyTypedAsAny: false ,
102
+ allowDirectConstAssertionInArrowFunctions : true ,
103
103
allowedNames: [],
104
- shouldTrackReferences: true ,
104
+ allowHigherOrderFunctions: true ,
105
+ allowTypedFunctionExpressions: true ,
105
106
};
106
107
```
107
108
@@ -127,83 +128,20 @@ If you are working on a codebase within which you lint non-TypeScript code (i.e.
127
128
}
128
129
```
129
130
130
- ### ` allowTypedFunctionExpressions `
131
-
132
- Examples of ** incorrect** code for this rule with ` { allowTypedFunctionExpressions: true } ` :
133
-
134
- ``` ts
135
- export let arrowFn = () => ' test' ;
136
-
137
- export let funcExpr = function () {
138
- return ' test' ;
139
- };
140
-
141
- export let objectProp = {
142
- foo : () => 1 ,
143
- };
144
-
145
- export const foo = bar => {};
146
- ```
131
+ ### ` allowArgumentsExplicitlyTypedAsAny `
147
132
148
- Examples of additional ** correct ** code for this rule with ` { allowTypedFunctionExpressions : true } ` :
133
+ Examples of ** incorrect ** code for this rule with ` { allowArgumentsExplicitlyTypedAsAny : true } ` :
149
134
150
135
``` ts
151
- type FuncType = () => string ;
152
-
153
- export let arrowFn: FuncType = () => ' test' ;
154
-
155
- export let funcExpr: FuncType = function () {
156
- return ' test' ;
157
- };
158
-
159
- export let asTyped = (() => ' ' ) as () => string ;
160
- export let castTyped = <() => string >(() => ' ' );
161
-
162
- interface ObjectType {
163
- foo(): number ;
164
- }
165
- export let objectProp: ObjectType = {
166
- foo : () => 1 ,
167
- };
168
- export let objectPropAs = {
169
- foo : () => 1 ,
170
- } as ObjectType ;
171
- export let objectPropCast = <ObjectType >{
172
- foo : () => 1 ,
173
- };
174
-
175
- type FooType = (bar : string ) => void ;
176
- export const foo: FooType = bar => {};
177
- ```
178
-
179
- ### ` allowHigherOrderFunctions `
180
-
181
- Examples of ** incorrect** code for this rule with ` { allowHigherOrderFunctions: true } ` :
182
-
183
- ``` ts
184
- export var arrowFn = () => () => {};
185
-
186
- export function fn() {
187
- return function () {};
188
- }
189
-
190
- export function foo(outer ) {
191
- return function (inner ): void {};
192
- }
136
+ export const func = (value : any ): void => ({ type: ' X' , value });
137
+ export function foo(value : any ): void {}
193
138
```
194
139
195
- Examples of ** correct** code for this rule with ` { allowHigherOrderFunctions : true } ` :
140
+ Examples of ** correct** code for this rule with ` { allowArgumentsExplicitlyTypedAsAny : true } ` :
196
141
197
142
``` ts
198
- export var arrowFn = () => (): void => {};
199
-
200
- export function fn() {
201
- return function (): void {};
202
- }
203
-
204
- export function foo(outer : string ) {
205
- return function (inner : string ): void {};
206
- }
143
+ export const func = (value : number ): void => ({ type: ' X' , value });
144
+ export function foo(value : number ): void {}
207
145
```
208
146
209
147
### ` allowDirectConstAssertionInArrowFunctions `
@@ -248,26 +186,83 @@ You may pass function/method names you would like this rule to ignore, like so:
248
186
}
249
187
```
250
188
251
- ### ` shouldTrackReferences `
189
+ ### ` allowHigherOrderFunctions `
252
190
253
- Examples of ** incorrect** code for this rule with ` { shouldTrackReferences : true } ` :
191
+ Examples of ** incorrect** code for this rule with ` { allowHigherOrderFunctions : true } ` :
254
192
255
193
``` ts
256
- function foo(bar ) {
257
- return bar ;
194
+ export var arrowFn = () => () => {};
195
+
196
+ export function fn() {
197
+ return function () {};
258
198
}
259
199
260
- export default foo ;
200
+ export function foo(outer ) {
201
+ return function (inner ): void {};
202
+ }
261
203
```
262
204
263
- Examples of ** correct** code for this rule with ` { shouldTrackReferences : true } ` :
205
+ Examples of ** correct** code for this rule with ` { allowHigherOrderFunctions : true } ` :
264
206
265
207
``` ts
266
- function foo(bar : string ): string {
267
- return bar ;
208
+ export var arrowFn = () => (): void => {};
209
+
210
+ export function fn() {
211
+ return function (): void {};
212
+ }
213
+
214
+ export function foo(outer : string ) {
215
+ return function (inner : string ): void {};
268
216
}
217
+ ```
218
+
219
+ ### ` allowTypedFunctionExpressions `
220
+
221
+ Examples of ** incorrect** code for this rule with ` { allowTypedFunctionExpressions: true } ` :
269
222
270
- export default foo ;
223
+ ``` ts
224
+ export let arrowFn = () => ' test' ;
225
+
226
+ export let funcExpr = function () {
227
+ return ' test' ;
228
+ };
229
+
230
+ export let objectProp = {
231
+ foo : () => 1 ,
232
+ };
233
+
234
+ export const foo = bar => {};
235
+ ```
236
+
237
+ Examples of additional ** correct** code for this rule with ` { allowTypedFunctionExpressions: true } ` :
238
+
239
+ ``` ts
240
+ type FuncType = () => string ;
241
+
242
+ export let arrowFn: FuncType = () => ' test' ;
243
+
244
+ export let funcExpr: FuncType = function () {
245
+ return ' test' ;
246
+ };
247
+
248
+ export let asTyped = (() => ' ' ) as () => string ;
249
+ export let castTyped = <() => string >(() => ' ' );
250
+
251
+ interface ObjectType {
252
+ foo(): number ;
253
+ }
254
+ export let objectProp: ObjectType = {
255
+ foo : () => 1 ,
256
+ };
257
+ export let objectPropAs = {
258
+ foo : () => 1 ,
259
+ } as ObjectType ;
260
+ export let objectPropCast = <ObjectType >{
261
+ foo : () => 1 ,
262
+ };
263
+
264
+ type FooType = (bar : string ) => void ;
265
+ export const foo: FooType = bar => {};
271
266
```
272
267
273
268
## When Not To Use It
0 commit comments