-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[explicit-function-return-type] Consider allowExpressions=true and allowTypedFunctionExpressions=true as default #493
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
Comments
I 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. |
see detail: typescript-eslint/typescript-eslint#493 [explicit-function-return-type] Consider allowExpressions=true and allowTypedFunctionExpressions=true as default
There's a few more cases where explicit types are redundant and annoying:
class Foo extends React.Component {
render(): React.ReactNode /* duh */ { return <h1>Hello</h1> }
}
// mobx-state-tree
const Foo = types.snapshotProcessor(Bar, {
preProcessor(snapshot: BackendFoo): Something {
return { text: snapshot.text || "" }
},
postProcessor(snapshot): BackendFoo {
return { text: !snapshot.text ? null : sn.text }
},
}) |
@bradzacher You may have forgotten to update the docs? |
I did indeed. |
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: