Reputation: 8886
In my React TypeScript file, I have the following code:
<Button onClick={() => handleClick()}
This throws the following linting error.
Missing return type on function.eslint@typescript-eslint/explicit-function-return-type
To solve the error, I added a void return type to the arrow function:
<Button onClick={(): void => handleClick()}
But is it the right way to declare return type for all such functions, because they will always be void? Or should the rule be disabled for such arrow function expressions?
Upvotes: 1
Views: 4924
Reputation: 89
Depending on the project. I prefer at the moment follow the community standards. This is a good article to understand extending rules and how to use it: Better linting with Typescript and custom ESLint. However I was working in a project where the architect made eslint rules such as allways adding "readonly" in each attr obj (this was very tedious if you haven't good snippets...).
To deactivate or modify any eslint rule go to eslint.rc file
"rules": {
"typescript-eslint/explicit-function-return-type": "off",
},
Here is the documentation with all info. Take a look if there is a mid solution instead of deactivate it :)
Upvotes: 2