Saj*_*ard 5 javascript typescript reactjs
我正在使用 React + typescript,并遇到了有关渲染组件的问题。
这是我尝试过的代码
filterCellComponent = ({ column, ...restProps }) => (
<TableFilterRow.Cell
column={column}
{...restProps} />
);
Run Code Online (Sandbox Code Playgroud)
在上面的方法中,我使用 {column} 变量来执行一些条件,然后使用 {...restProps} 进行渲染。但我收到一个语法错误,说缺少一些道具。但是当我调试时,所需的所有道具都位于 {...restProps} 变量内。我不明白为什么会发生这种情况。
知道为什么会发生这种情况吗?
谢谢
似乎打字稿无法确定column. 尝试在函数签名中指定类型,如下所示:
filterCellComponent = ({column, ...restProps}:InsertTypeHere) => (
Run Code Online (Sandbox Code Playgroud)
澄清一下,问题是filterCellComponent现在接受任何具有列属性的对象。但TableFilterRow.Cell想column成为一个特定的类型。