Typescript | Warning about Missing Return Type of function, ESLint

Dimitris Efst

I have a REACT-STATELESS-COMPONENT, in a project with TypeScript. It has an error, saying, that

Missing return type on function.eslint(@typescript-eslint/explicit-function-return-type)

I am not sure what it wants me to do. Here is my code:

import React, { Fragment} from 'react';
import IProp from 'dto/IProp';

export interface Props {
  prop?: IProp;
}

const Component = <T extends object>({ prop }: Props & T) => (
  <Fragment>
    {prop? (
      <Fragment>
        Some Component content..
      </Fragment>
    ) : null}
  </Fragment>
);

LicenseInfo.defaultProps: {};

export default Component;

Can you tell me what I need to do. I need to read about TS, but currently I don't get it at all. And I can't commit right now cause of this.

Nicholas Tower

I'd recommend using the types provided by react; they'll include the return type. If you're on the version 16.8.0 or later of react, do this:

const Component: React.FunctionComponent<Props> = (props) => (

Or use the shorthand:

const Component: React.FC<Props> = (props) => (

Prior to 16.8, you'd instead do:

const Component: React.SFC<Props> = (props) => (

Where SFC stands for "stateless functional component". They changed the name, since function components are no longer necessarily stateless.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Eslint warning about super(props) removing it breaks code

From Java

Specify return type in TypeScript arrow function

From Java

TypeScript function return type based on input parameter

From Java

TypeScript: Is it possible to get the return type of a generic function?

From Dev

UICollectionReusableView - Missing return in a function

From Dev

Is it possible in typescript to have a function return the type of a class that extends it

From Dev

When a function missing the return value, the compiler generates a warning but not an error?

From Dev

Confused about the function return value

From Dev

How can I define a return type of void for a function in a Typescript interface?

From Dev

How can I define the return type of a lodash reduce function with Typescript?

From Dev

Confusion about return function and Monad

From Dev

Missing warning about variable might not have initialized

From Dev

Issue about function overloads with different return type

From Dev

return type for class function typescript

From Dev

What return type should I declare a function with if I don't care about the return value?

From Dev

Visual Studio warning about function not in global namespace

From Dev

Typescript: Constrain function generic type based on the expected return type

From Dev

Warning about parameters in XGBoost function in Python?

From Dev

Typescript: function return object type with field from parameter

From Dev

Generic return type of function in Typescript

From Dev

Blue bird return promise missing warning

From Dev

TypeScript return exact function infer type

From Dev

Minimal implementation of function with conditional type return type in TypeScript

From Dev

Typescript - Function return type if I want to return object

From Dev

Implementing a function with conditional return type in Typescript

From Dev

Why after wrapping function that return object in useMemo I get warning about non function?

From Dev

Typescript throws error for return function type

From Dev

Typescript function return type depending on number or type of arguments

From Dev

Warning about parameters in XGBoost function in Python?

Related Related

  1. 1

    Eslint warning about super(props) removing it breaks code

  2. 2

    Specify return type in TypeScript arrow function

  3. 3

    TypeScript function return type based on input parameter

  4. 4

    TypeScript: Is it possible to get the return type of a generic function?

  5. 5

    UICollectionReusableView - Missing return in a function

  6. 6

    Is it possible in typescript to have a function return the type of a class that extends it

  7. 7

    When a function missing the return value, the compiler generates a warning but not an error?

  8. 8

    Confused about the function return value

  9. 9

    How can I define a return type of void for a function in a Typescript interface?

  10. 10

    How can I define the return type of a lodash reduce function with Typescript?

  11. 11

    Confusion about return function and Monad

  12. 12

    Missing warning about variable might not have initialized

  13. 13

    Issue about function overloads with different return type

  14. 14

    return type for class function typescript

  15. 15

    What return type should I declare a function with if I don't care about the return value?

  16. 16

    Visual Studio warning about function not in global namespace

  17. 17

    Typescript: Constrain function generic type based on the expected return type

  18. 18

    Warning about parameters in XGBoost function in Python?

  19. 19

    Typescript: function return object type with field from parameter

  20. 20

    Generic return type of function in Typescript

  21. 21

    Blue bird return promise missing warning

  22. 22

    TypeScript return exact function infer type

  23. 23

    Minimal implementation of function with conditional type return type in TypeScript

  24. 24

    Typescript - Function return type if I want to return object

  25. 25

    Implementing a function with conditional return type in Typescript

  26. 26

    Why after wrapping function that return object in useMemo I get warning about non function?

  27. 27

    Typescript throws error for return function type

  28. 28

    Typescript function return type depending on number or type of arguments

  29. 29

    Warning about parameters in XGBoost function in Python?

HotTag

Archive