-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Repro
"rules": {
"@typescript-eslint/explicit-function-return-type": [
"warn",
{
"allowTypedFunctionExpressions": true,
"allowHigherOrderFunctions": true
}
],
}
type MyFunctionType = (randomString: string) => string;
type InjectString<T> = (injectedString: string) => T;
const myfunction: InjectString<MyFunctionType> = injectedString => input => injectedString + input; // rule complains of missing return
const myFunctionAfterInjection = myfunction('potato'); // TS correctly infers a result of type MyFunctionType
const myFunctionResolved = myFunctionAfterInjection('anotherPotato'); // TS correctly infers a result of type string
Expected Result
Since
a) my function is already typed
b) I've marked as true both allowTypedFunctionExpressions and allowHigherOrderFunctions
c) Typescript is able to handle inference fine
I would expect the rule to accept this as an explicitly typed return type
Actual Result
The rule forces me to state the last return explicitly.
Additional Info
I could see how some people would prefer the last return function to be explicitly stated anyway, but I can't find a way to make my preference work: Typing just the function, but keeping the rule active for cases where the return type hasn't been stated in the function itself nor in the return type. I would like either dropping the need of the last return, a new option that handles this use case or a different rule if this is considered out of the scope for this specific rule - any way that can handle the use case would be fine.
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
1.13.0 |
@typescript-eslint/parser |
1.9.0 |
TypeScript |
3.4.5 |
ESLint |
5.10.0 |
node |
10.15.3 |
npm |
6.4.1 |