Is there a way to achieve intellisense for an object created with a dynamic class by passing parameters?
Here is the code snippet:
Main:
let ita: any = new DynamicClass('ITA');
let deu: any = new DynamicClass('DEU');
The DynamicClass used to create dynamic classes:
export class DynamicClass {
constructor(className: string) {
if (Store[className] === undefined || Store[className] === null) {
throw new Error(`Class type of \'${className}\' is not in the store`);
}
return new Store[className];
}
}
Sample dynamic classes ITA and DEU:
export class ITA {
id: string;
name: string;
pck: string;
constructor() {
console.log('ITA class');
this.id = '1';
this.name = 'ita';
this.pck = '4';
}
}
export class DEU {
id: string;
name: string;
size: string;
constructor() {
console.log('DEU class');
this.id = '1';
this.name = 'ita';
this.size = '5';
}
}
export const Store: any = {
ITA,
DEU,
}