在以下的代码片段中,
type T1 = React.Component;
type T2 = typeof React.Component;
T1和T2有什么区别?
再深入一步,给定以下的定义:
class CardHeader extends React.Component {...}
和一个在别处定义的用来渲染它的function:
- Function定义#1
function renderCardHeader(Comp: React.Component) {
return <Comp />;
}
- Function定义#2
function renderCardHeader(Comp: typeof React.Component) {
return <Comp />;
}
Function定义#1在TS 2.9.2中会在<Comp />
处报错:
JSX element type 'Comp' does not have any construct or call signatures.
这是为什么?难道React.Component
不是一个type吗?
还有,在Function定义#2中,Comp: typeof React.Component
,一个type的type是什么?