Sajad Jaward
Sajad Jaward

Reputation: 357

Spread operator is not working in react typescript

I am using React + typescript and encountered with a problem regarding rendering a component.

Here is the code of what I have tried

filterCellComponent = ({ column, ...restProps }) => (
        <TableFilterRow.Cell
            column={column}
            {...restProps} />
    );

In the above method, i use the {column} variable to perform some conditions and then I render the with use of {...restProps}. But I am getting a syntax error saying some props are missing. But when I debug, all the props that are required are inside the {...restProps} variable. I do not understand why this is happening.

Here is the image that shows the error: enter image description here

And this is the error message that i'm getting enter image description here

Any idea on why this is happening?

Thanks

Upvotes: 5

Views: 4321

Answers (1)

pgsandstrom
pgsandstrom

Reputation: 14399

It seems as if typescript cant determine the type of column. Try specifying the types in the function signature like this:

filterCellComponent = ({column, ...restProps}:InsertTypeHere) => (

To clarify, the problem is that filterCellComponent right now accepts any object that has a column-property. But TableFilterRow.Cell wants column to be a specific type.

Upvotes: 5

Related Questions