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 thatfilterCellComponent
's signature doesn't declare any types. It's type usage is not deterministic, so TS assumesany
. 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 useCell
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
1 Answer
Reset to default 5It 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
版权声明:本文标题:javascript - Spread operator is not working in react typescript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745265299a2650562.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论