-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[explicit-function-return-type] request option for curried arrow functions #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
enhancement: plugin rule option
New rule option for an existing eslint-plugin rule
has pr
there is a PR raised to close this
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
Comments
good idea and pretty easy to implement! |
Any news about this issue? |
Accepting PRs from the community (we love new contributors!!) |
I think I actually managed to implement it! 😳 #538 🎉 |
JamesHenry
pushed a commit
that referenced
this issue
Jun 3, 2019
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
enhancement: plugin rule option
New rule option for an existing eslint-plugin rule
has pr
there is a PR raised to close this
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
Proposal
Additional option for
explicit-function-return-type
ignores all but the final returned function when multiple fat-arrows appear in a function expression before a shared body.Purpose
In functional programming, currying is a common pattern. With this pattern a function taking multiple parameters is instead modeled as a unary (1-parameter) function that returns a unary function that returns a unary function, .etc. With arrow functions, you can express this quite elegantly, but the intermediate return types are (usually) not of meaningful importance.
Example
Good: Explicit return given for last function returned by expression.
Bad: Applied all parameters, but still failed to express a return type.
Note that in the example, there are technically 4 different functions in the
foo
expression. But from a conceptual level, you can think of it as 1 function that must be called 4 times to apply all the parameters.The type of
foo( 'bar' )
is "foo
with the first parameter fixed as'bar'
". Trying to express that explicitly through the type system is a painful exercise in meaningless verbosity.However, once all the parameters are given, it still makes sense to enforce an explicit return type for the final returned value.
The text was updated successfully, but these errors were encountered: