Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'Element[]' is missing the following properties from type 'Element': type, props, key

I have the standard arrow map ES7 function with Typescript and React environment:

 const getItemList: Function = (groups: any[]): JSX.Element =>    group.map((item: any, i: number) => {     const itemCardElemProps = { handleEvents: () => {}, ...item}     return <Item key={`${item.id}_${i}`} {...itemCardElemProps} />   }) 

and get the error:

TS2739: Type 'Element[]' is missing the following properties from type 'Element': type, props, key 

Version: typescript 3.5.3

like image 241
Roman Avatar asked Oct 09 '19 19:10

Roman


People also ask

Is missing the following properties from type type props key?

The React. js error "Type is missing the following properties from type" occurs when we don't pass any props to a component, or don't pass it all of the props it requires. To solve the error, make sure to provide all of the props that are required in the component.

Is missing the following properties from type typescript?

The error "Type is missing the following properties from type" occurs when the type we assign to a variable is missing some of the properties the actual type of the variable expects. To solve the error, make sure to specify all of the required properties on the object.

What is react createElement?

React. createElement( type, [props], [... children] ) Create and return a new React element of the given type. The type argument can be either a tag name string (such as 'div' or 'span' ), a React component type (a class or a function), or a React fragment type.

Does not have any construct or call signatures?

The error "JSX element type does not have any construct or call signatures" occurs when we try to pass an element or a react component as props to another component but type the prop incorrectly. To solve the error, use the React. ElementType type.


1 Answers

You could always just send back a single JSX.Element as a fragment, too:

interface IOptions {    options: string[] }  const CardArray: React.FC<IOptions> = ({ options }) => {    return <>{options.map(opt => opt)}</> } 

This way you're matching the returned type and it won't affect your markup.

like image 68
andrewmart.in Avatar answered Sep 21 '22 08:09

andrewmart.in