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

Typescript 如何断言React.Component实例的返回类型?,typescript,react-jsx,jsx,Typescript,React Jsx,Jsx,在typescript中,我有一个React组件,Cell 我试图断言返回值是Cell的一个实例,而不是JSX.Element 使用React.ReactElement。e、 g const foo: React.ReactElement<Cell> = <Cell/>; // Okay const bar: React.ReactElement<Cell> = <NotCell/>; // Error! const foo:React.Reac

在typescript中,我有一个React组件,Cell

我试图断言返回值是Cell的一个实例,而不是JSX.Element

使用
React.ReactElement
。e、 g

const foo: React.ReactElement<Cell> = <Cell/>; // Okay
const bar: React.ReactElement<Cell> = <NotCell/>; // Error!
const foo:React.ReactElement=;//可以
常量栏:React.ReactElement=;//错误!

请显示您的断言。如果
单元格
是一个功能组件,有没有办法强制执行相同的约束?
<Cell />
Type `Element` is not assignable to type `Cell`
const foo: React.ReactElement<Cell> = <Cell/>; // Okay
const bar: React.ReactElement<Cell> = <NotCell/>; // Error!