React with 16-fragment functional component and typescript TS2605

I am using tsx with React. My early days with React and not too much knowledge about Typescript.


@ types / react 16.0.25

respond 16.1.1


In my tsconfig.json, I have "noImplicitAny": false

When I write a functional component that returns a fragment:

function MyComponent() {
    return [<div>1</div>, <div>2</div>];
}

Typescript complains:

    TS2605: JSX element type 'Element[]' is not a constructor function for JSX elements.
  Property 'render' is missing in type 'Element[]'.

If I define type: any, I miss the error

function MyComponent():any {
    return [<div>1</div>, <div>2</div>];
}

Is this a problem from @ types / response or am I doing something wrong?

+4
source share

Source: https://habr.com/ru/post/1689805/


All Articles