简体   繁体   中英

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: 在此处输入图片说明

And this is the error message that i'm getting 在此处输入图片说明

Any idea on why this is happening?

Thanks

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM