[explicit-function-return-type] Consider allowExpressions=true and allowTypedFunctionExpressions=true as default #493
Labels
breaking change
This change will require a new major version to be released
enhancement
New feature or request
has pr
there is a PR raised to close this
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
Milestone
Uh oh!
There was an error while loading. Please reload this page.
Repro
We were disabling the
explicit-function-return-type
rule, until a version was released with both theallowExpressions
andallowTypedFunctionExpressions
options:Without these overrides, function return types must be explicitly set, even if type annotations are defined on the variable of a function expression. From what I've seen nearly all (if not all) function typedefs include the return type (specifically in the React world). For this reason, needing to define the return type becomes repetitive and cumbersome, because you then have to dig into the typedefs of the variable type to understand the return value definition (without any additional value-add).
For example:
The same is true for
allowExpressions
. For example, consider the following:The
useMemo
typedef is set up to infer the type based on the return value of the function. We know this, because you cannot do this:However, without
allowExpressions
set totrue
, we must specify the following:Your team may have some metrics on this, but it would be interesting to see from the community just what percentage of folks actually feel there is value in inheriting the return type from the variable definition - for both function expressions and declarations.
Please consider
allowTypedFunctionExpressions=true
andallowExpressions=true
as the default case for@typescript-eslint/explicit-function-return-type
. My assumption is that the majority of folks would then be able to use the plugin as-is out-of-the-box, without any customizations - including ourselves.References
Versions
@typescript-eslint/eslint-plugin
1.7.0
@typescript-eslint/parser
1.7.0
TypeScript
3.4.1
ESLint
5.16.0
node
10.15.3
npm
6.9.0
The text was updated successfully, but these errors were encountered:
[explicit-function-return-type] Consider allowTypedFunctionExpressions=true as default[explicit-function-return-type] Consider allowExpressions=true and allowTypedFunctionExpressions=true as defaultI was actually planning on making this the default with the next breaking change.
It makes a lot more sense to have all of these options turned on, esp considering that so many people assume it works out of the box for all of the cases.
That's awesome @bradzacher. I will keep an eye on upcoming major version bumps' changelog.
chore(settings): improve eslint rules for typescript
bda6f6f
There's a few more cases where explicit types are redundant and annoying:
@phaux
This issue isn't a place for enhancement requests to the rule. Please raise a new issue if you'd like to discuss these.
1 - see discussion on #541
2 - feel free to open a new issue for this request.
@bradzacher You may have forgotten to update the docs?
I did indeed.
Fixed 989c13a