Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Typed signature required for parameterless functions #4191

Closed
sambokai opened this issue Sep 26, 2018 · 4 comments
Closed

Typed signature required for parameterless functions #4191

sambokai opened this issue Sep 26, 2018 · 4 comments

Comments

@sambokai
Copy link

sambokai commented Sep 26, 2018

Bug Report

  • TSLint version: 5.11.0
  • TypeScript version: 3.0.3
  • Running TSLint via: tslint-loader (webpack loader)

TypeScript code being linted

Simplified:

const Hello = () => <h3>Hello GitHub</h3>;

Actual use case:

const mapDispatchToProps = (dispatch: Dispatch) => ({
    doSomething: () => dispatch("Placeholder"),
});

tslint.json configuration:

{
  "extends": ["tslint:latest", "tslint-react"],
  "rules": {
    "quotemark": [true, "single", "jsx-double"],
    "interface-name": [true, "never-prefix"],
    "no-implicit-dependencies": [true, "dev"],
    "typedef": [
      true,
      "call-signature",
      "arrow-call-signature",
      "property-declaration",
      "parameter",
      "arrow-parameter"
    ]
  }
}

Actual behavior

TSLint throws an expected arrow-call-signature to have a typedef warning at the above code.

Expected behavior

ESLint should not require typed signature for parameterless (arrow) functions


Thank you very much guys

@JoshuaKGoldberg
Copy link
Contributor

Note: this is visually similar to #2000 but more severe.

@nathanredblur
Copy link

nathanredblur commented Jan 24, 2019

My case is similar, I have this code:

type Props = {
  children: React.ReactNode;
  classNames?: string;
  handleOnClick: () => void;
}

const Button: React.FunctionComponent<Props> = ({
  children,
  classNames = '',
  handleOnClick,
}) => (
  <button
    type="button"
    className={`${classNames} Button flex-center-center`}
    onClick={handleOnClick}
  >
    {children}
  </button>
);

this interface React.FunctionComponent has all but the rules that comes from "tslint-microsoft-contrib" force me to redefine the function input and outputs

[tslint] expected arrow-call-signature to have a typedef (typedef) [1]
[tslint]
expected arrow-parameter: '{
  children,
  classNames = '',
  handleOnClick,
}' to have a typedef (typedef) [1]

@VincentLanglet
Copy link
Contributor

@JoshuaKGoldberg I dont see bug here.

@sambokai

const mapDispatchToProps = (dispatch: Dispatch) => ({
    doSomething: () => dispatch("Placeholder"),
});

should be

const mapDispatchToProps = (dispatch: Dispatch): Foo => ({
    doSomething: (): Bar => dispatch("Placeholder"),
});

@nathanredblur

const Button: React.FunctionComponent<Props> = ({
  children,
  classNames = '',
  handleOnClick,
}) => (
  <button
    type="button"
    className={`${classNames} Button flex-center-center`}
    onClick={handleOnClick}
  >
    {children}
  </button>
);

should be

const Button: React.FunctionComponent<Props> = ({
  children,
  classNames = '',
  handleOnClick,
}: Foo): Bar => (
  <button
    type="button"
    className={`${classNames} Button flex-center-center`}
    onClick={handleOnClick}
  >
    {children}
  </button>
);

@adidahiya
Copy link
Contributor

agreed with @VincentLanglet

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants