Skip to content
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

[explicit-function-return-type] Correct return type for React function components #814

Closed
flopes89 opened this issue Aug 7, 2019 · 4 comments
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin question Questions! (i.e. not a bug / enhancment / documentation)

Comments

@flopes89
Copy link

flopes89 commented Aug 7, 2019

Repro

{
  "extends": "plugin:@typescript-eslint/recommended"
}
const MyComp: React.FC<MyProps> = (props): ???? => {
   return (
      <div>Hello World</div>
   );
};

What's the correct/recommended return type for the function when this rule tells me that I am required to use one?

I would assume it's inferred, but that doesn't seem to happen?

Versions

package version
@typescript-eslint/eslint-plugin 1.13.0
@typescript-eslint/parser 1.13.0
TypeScript 3.4.3
ESLint 5.16.0
node 10.15.3
npm 6.4.1
@flopes89 flopes89 added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Aug 7, 2019
@flopes89 flopes89 changed the title [explicit-function-return-type] <issue title> [explicit-function-return-type] Recommendations for React function components Aug 7, 2019
@flopes89 flopes89 changed the title [explicit-function-return-type] Recommendations for React function components [explicit-function-return-type] Correct return type for React function components Aug 7, 2019
@bradzacher
Copy link
Member

A few ways:

  • if you use go to definition, you'll be able to find out the expected return type of the React.FC
  • if you delete the React.FC type and mouse over the variable name, it'll show you the expected return type

Also please consider reading the rule docs, as you can use the allowTypedFunctionExpressions option to avoid having to explicitly type this function.

@bradzacher bradzacher added question Questions! (i.e. not a bug / enhancment / documentation) and removed triage Waiting for maintainers to take a look labels Aug 7, 2019
@flopes89
Copy link
Author

flopes89 commented Aug 7, 2019

I know about the options, I'm just wondering if it makes sense to have them in the recommended configuration like they are.

@bradzacher
Copy link
Member

#729 and friends.

It's going to be turned on by default in v2.

@flopes89
Copy link
Author

flopes89 commented Aug 7, 2019

Aaah I see, perfect! Thanks :)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin question Questions! (i.e. not a bug / enhancment / documentation)
Projects
None yet
Development

No branches or pull requests

2 participants