Reactjs 反应&;TypeScript-what';“React.Component”和“typeof React.Component”的区别是什么`

Reactjs 反应&;TypeScript-what';“React.Component”和“typeof React.Component”的区别是什么`,reactjs,typescript,Reactjs,Typescript,鉴于: T1和T2有什么区别 进一步问题。给定以下类定义: type T1 = React.Component; type T2 = typeof React.Component; 以及一个在其他地方渲染的函数: 功能定义#1: 我很困惑,React.Component不是一种类型吗 至于#2,Comp:typeof React.Component,另一种类型的类型是什么?有了typeof,就得到了实例的类型,类基本上有两个方面。静态端(包含构造函数/静态变量和方法)和实例端(包含非静态内容

鉴于:

T1和T2有什么区别


进一步问题。给定以下类定义:

type T1 = React.Component;
type T2 = typeof React.Component;
以及一个在其他地方渲染的函数:

功能定义#1:

我很困惑,
React.Component
不是一种类型吗


至于#2,
Comp:typeof React.Component
,另一种类型的类型是什么?

有了typeof,就得到了实例的类型,类基本上有两个方面。静态端(包含构造函数/静态变量和方法)和实例端(包含非静态内容)

当您使用typeof(class)时,您指的是类的静态端,因此有效的类型只是类而不是类的实例

这里有一个例子:

class-Foo{
静态staticMethod(){}
instanceMethod(){}
}
类栏扩展了Foo{}
//实例端
常量fooInstance2:Foo=newbar();
const Foo实例:Foo=new Foo();
fooInstance.instanceMethod();
//静态侧
常量fooClass2:typeof Foo=Bar;
const Foo类:typeof Foo=Foo;
fooClass.staticMethod();
//错误,因为静态端和实例端不同
const fooClass3:typeof Foo=new Foo();
class CardHeader extends React.Component {...}
function renderCardHeader(Comp: React.Component) {
    return <Comp />;
}
function renderCardHeader(Comp: typeof React.Component) {
    return <Comp />;
}
JSX element type 'Comp' does not have any construct or call signatures.