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] Don't report when using an explicit variable type with an arrow function #149

Closed
cheezenaan opened this issue Jan 27, 2019 · 14 comments

Comments

@cheezenaan
Copy link

@cheezenaan cheezenaan commented Jan 27, 2019

Repro

{
  "extends": ["plugin:@typescript-eslint/recommended"],
  "plugins": ["react"]
}
import * as React from 'react';

interface Props {
    message?: string;
}

export const Hello: React.SFC<Props> = ({ message = 'kiniro-mosaic' }) => (
    <div>{`Hello! ${message}`}</div>;
);

Expected Result

Neither errors nor warnings

Actual Result

7:40  warning  Missing return type on function  @typescript-eslint/explicit-function-return-type

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 1.1.0
@typescript-eslint/parser 1.1.0
eslint-plugin-react 7.12.4
react 16.7.0
react-dom 16.7.0
TypeScript 3.2.4
ESLint 5.12.1
node 8.11.3
npm 5.6.0
@bradzacher bradzacher changed the title [explicit-function-return-type] Show warnings when using React.SFC [explicit-function-return-type] Don't report when using an explicit variable type with an arrow function Jan 27, 2019
gilbsgilbs added a commit to gilbsgilbs/typescript-eslint that referenced this issue Feb 12, 2019
gilbsgilbs added a commit to gilbsgilbs/typescript-eslint that referenced this issue Feb 12, 2019
gilbsgilbs added a commit to gilbsgilbs/typescript-eslint that referenced this issue Feb 12, 2019
gilbsgilbs added a commit to gilbsgilbs/typescript-eslint that referenced this issue Feb 12, 2019
gilbsgilbs added a commit to gilbsgilbs/typescript-eslint that referenced this issue Feb 14, 2019
gilbsgilbs added a commit to gilbsgilbs/typescript-eslint that referenced this issue Feb 14, 2019
gilbsgilbs added a commit to gilbsgilbs/typescript-eslint that referenced this issue Feb 15, 2019
gilbsgilbs added a commit to gilbsgilbs/typescript-eslint that referenced this issue Feb 16, 2019
gilbsgilbs added a commit to gilbsgilbs/typescript-eslint that referenced this issue Feb 16, 2019
@codepunkt
Copy link

@codepunkt codepunkt commented Feb 19, 2019

Is this the same problem?

type Wat = () => string[]

// Missing return type on function.eslint(@typescript-eslint/explicit-function-return-type)
let fn: Wat = () => {
  return []
}
type Wat = () => string[]

// no errors or warnings
let fn: Wat
fn = () => {
  return []
}
@gilbsgilbs
Copy link
Contributor

@gilbsgilbs gilbsgilbs commented Feb 19, 2019

@codepunkt Yes.

@codepunkt
Copy link

@codepunkt codepunkt commented Feb 19, 2019

@gilbsgilbs can i help?

@gilbsgilbs
Copy link
Contributor

@gilbsgilbs gilbsgilbs commented Feb 19, 2019

@codepunkt I don't think so. I already made a PR that adds an option to ignore this rule when the function expression is typed. Just need to wait for merge and release.

bradzacher added a commit that referenced this issue Mar 21, 2019
#260)

Fixes #149 

Not sure if this is really acceptable though. Please tell me if it has some edge cases I didn't see or if it's just too broad.
@saranshkataria
Copy link

@saranshkataria saranshkataria commented Mar 27, 2019

I see the latest changes have been published, but I still get an error when writing this:

const App: React.FunctionComponent<{}> = () => <div>Hello World</div>;

@gilbsgilbs
Copy link
Contributor

@gilbsgilbs gilbsgilbs commented Mar 27, 2019

@saranshkataria thanks. I think it was only released as alpha at the moment. Just to be sure:

@bradzacher
Copy link
Member

@bradzacher bradzacher commented Mar 27, 2019

Yup, as @gilbsgilbs mentioned, this is only on the automatically released canary tag right now.
yarn add @typescript-eslint/eslint-plugin@canary

In future, please keep an eye on the releases section of the repo to see if PRs have released.
https://github.com/typescript-eslint/typescript-eslint/releases

@saranshkataria

This comment has been hidden.

@bradzacher

This comment has been hidden.

@kkalavantavanich

This comment has been hidden.

@gilbsgilbs

This comment has been hidden.

@TidyIQ

This comment has been hidden.

@TidyIQ
Copy link

@TidyIQ TidyIQ commented May 2, 2019

Nevermind, I just saw this issue that explains it. For anyone following along, the rule posted further up in the comments is incorrect. It should be:

  "rules": {
    "@typescript-eslint/explicit-function-return-type": ["error", {
      "allowTypedFunctionExpressions": true
    }],
  }
@ben-xD
Copy link

@ben-xD ben-xD commented Aug 11, 2019

May I ask why we need to set a rule for this? What is the alternative, and why don't we have it ignore missing return types for react components by default?

@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Feb 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

8 participants