Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

pass class to generic typescript

export class ImportedClass {
    public constructor(something: any) {
    }
    public async exampleMethod() {
        return "hey";
    }
}

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

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

PREVIOUS NEXT
Code Example
Typescript :: wordpress number of posts by user 
Typescript :: admin_enqueue_scripts specific page 
Typescript :: create mock promise angular 
Typescript :: path react native 
Typescript :: Already included file name react tsconfig 
Typescript :: Create Hash Node TypeScript 
Typescript :: react-excel-renderer nextjs error 
Typescript :: targe id that starts with 
Typescript :: enum as type typescript 
Typescript :: typescript variables 
Typescript :: calling contract method 
Typescript :: create react app with redux and typescript 
Typescript :: typescript value in enum 
Typescript :: Angular import from local library 
Typescript :: typescript union types 
Typescript :: path para imports firebase firestore 
Typescript :: input deno 
Typescript :: global declaration css ts 
Typescript :: difference between scripted testing and exploratory testing 
Typescript :: typescript date before 
Typescript :: prototype design pattern typescript 
Typescript :: typescript type specific numbers 
Typescript :: conventional commits cheat sheet 
Typescript :: accessing the elements of a char* in c 
Typescript :: this typescript 
Typescript :: c# merge two lists different types 
Typescript :: find elements by xpath with matching text 
Typescript :: typescript interview questions 
Typescript :: copy all elements from one list to another ajav 
Typescript :: sum all elements using each_with_object ruby 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =