@@ -65,13 +65,26 @@ The rule accepts an options object with the following properties:
65
65
66
66
``` ts
67
67
type Options = {
68
- // if true, type annotations are also allowed on the variable of a function expression rather than on the function directly
68
+ /**
69
+ * If true, type annotations are also allowed on the variable of a function expression
70
+ * rather than on the function arguments/return value directly.
71
+ */
69
72
allowTypedFunctionExpressions? : boolean ;
70
- // if true, functions immediately returning another function expression will not be checked
73
+ /**
74
+ * If true, functions immediately returning another function expression will not
75
+ * require an explicit return value annotation.
76
+ * You must still type the parameters of the function.
77
+ */
71
78
allowHigherOrderFunctions? : boolean ;
72
- // if true, body-less arrow functions are allowed to return an object as const
79
+ /**
80
+ * If true, body-less arrow functions that return an `as const` type assertion will not
81
+ * require an explicit return value annotation.
82
+ * You must still type the parameters of the function.
83
+ */
73
84
allowDirectConstAssertionInArrowFunctions? : boolean ;
74
- // an array of function/method names that will not be checked
85
+ /**
86
+ * An array of function/method names that will not have their arguments or their return values checked.
87
+ */
75
88
allowedNames? : string [];
76
89
};
77
90
@@ -118,6 +131,8 @@ export let funcExpr = function() {
118
131
export let objectProp = {
119
132
foo : () => 1 ,
120
133
};
134
+
135
+ export const foo = bar => {};
121
136
```
122
137
123
138
Examples of additional ** correct** code for this rule with ` { allowTypedFunctionExpressions: true } ` :
@@ -146,6 +161,9 @@ export let objectPropAs = {
146
161
export let objectPropCast = <ObjectType >{
147
162
foo : () => 1 ,
148
163
};
164
+
165
+ type FooType = (bar : string ) => void ;
166
+ export const foo: FooType = bar => {};
149
167
```
150
168
151
169
### ` allowHigherOrderFunctions `
@@ -158,6 +176,10 @@ export var arrowFn = () => () => {};
158
176
export function fn() {
159
177
return function () {};
160
178
}
179
+
180
+ export function foo(outer ) {
181
+ return function (inner ): void {};
182
+ }
161
183
```
162
184
163
185
Examples of ** correct** code for this rule with ` { allowHigherOrderFunctions: true } ` :
@@ -168,17 +190,15 @@ export var arrowFn = () => (): void => {};
168
190
export function fn() {
169
191
return function (): void {};
170
192
}
193
+
194
+ export function foo(outer : string ) {
195
+ return function (inner : string ): void {};
196
+ }
171
197
```
172
198
173
199
### ` allowDirectConstAssertionInArrowFunctions `
174
200
175
- Examples of additional ** correct** code for this rule with ` { allowDirectConstAssertionInArrowFunctions: true } ` :
176
-
177
- ``` ts
178
- export const func = (value : number ) => ({ type: ' X' , value } as const );
179
- ```
180
-
181
- Examples of additional ** incorrect** code for this rule with ` { allowDirectConstAssertionInArrowFunctions: true } ` :
201
+ Examples of ** incorrect** code for this rule with ` { allowDirectConstAssertionInArrowFunctions: true } ` :
182
202
183
203
``` ts
184
204
export const func = (value : number ) => ({ type: ' X' , value });
@@ -187,15 +207,34 @@ export const foo = () => {
187
207
bar: true ,
188
208
} as const ;
189
209
};
210
+ export const bar = () => 1 ;
211
+ export const baz = arg => arg as const ;
212
+ ```
213
+
214
+ Examples of ** correct** code for this rule with ` { allowDirectConstAssertionInArrowFunctions: true } ` :
215
+
216
+ ``` ts
217
+ export const func = (value : number ) => ({ type: ' X' , value } as const );
218
+ export const foo = () =>
219
+ ({
220
+ bar: true ,
221
+ } as const );
222
+ export const bar = () => 1 as const ;
223
+ export const baz = (arg : string ) => arg as const ;
190
224
```
191
225
192
226
### ` allowedNames `
193
227
194
228
You may pass function/method names you would like this rule to ignore, like so:
195
229
196
- ``` cjson
230
+ ``` json
197
231
{
198
- "@typescript-eslint/explicit-module-boundary-types": ["error", { "allowedName": ["ignoredFunctionName", "ignoredMethodName"] }]
232
+ "@typescript-eslint/explicit-module-boundary-types" : [
233
+ " error" ,
234
+ {
235
+ "allowedName" : [" ignoredFunctionName" , " ignoredMethodName" ]
236
+ }
237
+ ]
199
238
}
200
239
```
201
240
0 commit comments