javascript - Spread operator is not working in react typescript - Stack Overflow

I am using React + typescript and encountered with a problem regarding rendering a ponent.Here is the c

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745265300a4619417.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信