pass class to generic typescript

Solutions on MaxInterview for pass class to generic typescript by the best coders in the world

showing results for - "pass class to generic typescript"
Safa
01 Apr 2018
1export class ImportedClass {
2    public constructor(something: any) {
3    }
4    public async exampleMethod() {
5        return "hey";
6    }
7}
8
9interface GenericInterface<T> {
10    new(something: any): T;
11}
12
13export class Simulator<T extends { exampleMethod(): Promise<string> }> {
14    public constructor(private c: GenericInterface<T>) {
15    }
16    async work() {
17        const instanceTry = new this.c("hello");
18        await instanceTry.exampleMethod();
19    }
20}
21const simulator = new Simulator(ImportedClass);
22simulator.work()
23