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 · Fixed by #260
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@cheezenaan
Copy link

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
@cheezenaan cheezenaan added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Jan 27, 2019
@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
@bradzacher bradzacher added enhancement: plugin rule option New rule option for an existing eslint-plugin rule and removed triage Waiting for maintainers to take a look labels 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

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

@codepunkt Yes.

@codepunkt
Copy link

@gilbsgilbs can i help?

@gilbsgilbs
Copy link
Contributor

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.

@saranshkataria
Copy link

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

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

@bradzacher
Copy link
Member

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 minimized.

@bradzacher

This comment has been minimized.

@kkalavantavanich

This comment has been minimized.

@gilbsgilbs

This comment has been minimized.

@TidyIQ

This comment has been minimized.

@TidyIQ
Copy link

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 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.
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants