React.Component和typeof React.Component有什么区别?

新手上路,请多包涵

在以下的代码片段中,

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是什么?

阅读 2.4k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题