带有泛型扩展的typescript变量

带有泛型扩展的typescript变量,typescript,Typescript,我有一个预定义的界面: export declare interface Type<T> extends Function { new (...args: any[]): T; } 导出声明接口类型扩展函数{ 新(…args:any[]):T; } 我想要一个类属性来约束泛型类型。大概是这样的: public componentType: Type<any extends MyComponentType>; 公共组件类型:类型; 可能吗?因为我没有在Typ

我有一个预定义的界面:

export declare interface Type<T> extends Function {
    new (...args: any[]): T;
}
导出声明接口类型扩展函数{
新(…args:any[]):T;
}
我想要一个类属性来约束泛型类型。大概是这样的:

public componentType: Type<any extends MyComponentType>;
公共组件类型:类型;
可能吗?因为我没有在Typescript文档上找到解决方案,也找不到有效的语法


谢谢。

这是你想要的吗

export declare interface Type<A,T extends A = A> extends Function {
    new (...args: any[]): T;
}

class MyComponentType {

}

class MyComponentType2 extends MyComponentType{

}

class foo {
    public componentType: Type<MyComponentType>;

    constructor() {
        this.componentType = MyComponentType2;
    }
}
导出声明接口类型扩展函数{
新(…args:any[]):T;
}
类MyComponentType{
}
类MyComponentType2扩展了MyComponentType{
}
福班{
公共组件类型:类型;
构造函数(){
this.componentType=MyComponentType2;
}
}

答案是@Josh Wulf在原始帖子上的评论

public componentType: Type<MyComponentType>
公共组件类型:类型

也许可以给你一个答案为什么不干脆
公共组件类型:类型