小编And*_* G.的帖子

如何断言React.Component实例的返回类型?

在打字稿中,我有一个React Component,Cell,

class Cell extends Component<void, void> {
...
}
Run Code Online (Sandbox Code Playgroud)

当我使用它时,即

<Cell />
Run Code Online (Sandbox Code Playgroud)

我得到的返回类型是JSX.Element.

相反,我试图断言返回值是一个实例Cell,而不是JSX.Element,我怎么能这样做呢?

它失败了,因为它说

Type `Element` is not assignable to type `Cell`
Run Code Online (Sandbox Code Playgroud)

jsx typescript react-jsx

2
推荐指数
1
解决办法
595
查看次数

标签 统计

jsx ×1

react-jsx ×1

typescript ×1