admin管理员组

文章数量:1418425

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

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

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

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

Share Improve this question asked May 6, 2019 at 6:02 Sajad JawardSajad Jaward 3575 silver badges16 bronze badges 6
  • I think its not an error,may be its a warning – Rajesh Kumaran Commented May 6, 2019 at 6:13
  • 2 What are the propTypes accepted by Cell? The issue here is that filterCellComponent's signature doesn't declare any types. It's type usage is not deterministic, so TS assumes any. You need to declare it as accepting the Cell's propTypes. – hazardous Commented May 6, 2019 at 6:14
  • On a different note, why do you need filterCellComponent when it's not seem to be doing anything. Simply use Cell instead. – hazardous Commented May 6, 2019 at 6:15
  • @hazardous you are correct, by specifying the type for the props, it solved the syntax issue. thanks a bunch! – Sajad Jaward Commented May 6, 2019 at 6:25
  • @hazardous i actually simplified the method for better understanding. It's supposed to performs some logic and render few ponents based on certain conditions – Sajad Jaward Commented May 6, 2019 at 6:26
 |  Show 1 more ment

1 Answer 1

Reset to default 5

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.

本文标签: javascriptSpread operator is not working in react typescriptStack Overflow