Skip to content

[explicit-function-return-type] Don't report when using an explicit variable type with an arrow function #149

Closed
@cheezenaan

Description

@cheezenaan

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

Activity

added
package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
triageWaiting for team members to take a look
on Jan 27, 2019
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[/+] on Jan 27, 2019
added and removed
triageWaiting for team members to take a look
on Jan 27, 2019
added a commit that references this issue on Feb 12, 2019
3ec706f
added 8 commits that reference this issue on Feb 12, 2019
a9df636
51f25e4
871c9b1
d08e435
8a73cee
db9f929
17acfba
072afa5

7 remaining items

added a commit that references this issue on Mar 21, 2019
bea6b92
saranshkataria

saranshkataria commented on Mar 27, 2019

@saranshkataria

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

gilbsgilbs commented on Mar 27, 2019

@gilbsgilbs
Contributor

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

bradzacher

bradzacher commented on Mar 27, 2019

@bradzacher
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

saranshkataria commented on Mar 27, 2019

@saranshkataria
bradzacher

bradzacher commented on Mar 28, 2019

@bradzacher
kkalavantavanich

kkalavantavanich commented on Apr 18, 2019

@kkalavantavanich
gilbsgilbs

gilbsgilbs commented on Apr 18, 2019

@gilbsgilbs
TidyIQ

TidyIQ commented on May 2, 2019

@TidyIQ
TidyIQ

TidyIQ commented on May 2, 2019

@TidyIQ

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

ben-xD commented on Aug 11, 2019

@ben-xD

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?

locked as resolved and limited conversation to collaborators on Feb 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @codepunkt@cheezenaan@saranshkataria@gilbsgilbs@bradzacher

      Issue actions

        [explicit-function-return-type] Don't report when using an explicit variable type with an arrow function · Issue #149 · typescript-eslint/typescript-eslint