I tried to instantiate dynamically my class in a Vue JS with TypeScript project.
I tried this solution.
It works in Angular 2+ but in my Vue project I have this error :
Uncaught TypeError: Object prototype may only be an Object or null: undefined
I have a Classes.ts file
import {CMyClass} from 'path/to/my/class';
export const Classes = {
CMyClass: CMyClass
}
My class file :
import {CMyOtherClass} from 'path/to/my/mother/class';
export class CMyClass extends CMyOtherClass {
constructor() {}
}
My mother class file :
export class CMyOtherClass {
constructor() {}
}
And my function to instantiate a class :
import {Classes} from 'path/to/Classes/constante';
buildClass(className: string): any {
return new Classes[className]();
}
An idea ?