📜  将类传递给通用打字稿代码示例

📅  最后修改于: 2022-03-11 14:48:28.791000             🧑  作者: Mango

代码示例1
export class ImportedClass {
    public constructor(something: any) {
    }
    public async exampleMethod() {
        return "hey";
    }
}

interface GenericInterface {
    new(something: any): T;
}

export class Simulator }> {
    public constructor(private c: GenericInterface) {
    }
    async work() {
        const instanceTry = new this.c("hello");
        await instanceTry.exampleMethod();
    }
}
const simulator = new Simulator(ImportedClass);
simulator.work()