Is it possible to convert the following piece of code to work with Typescript?
public shops: string[] = [
"AShop",
"BShop",
"CShop",
];
this.shops.forEach((shop, index) => {
let instance = new window[shop](index);
this.instances.push(instance);
});
The following approach doesn't work with Typescript because window is inexistent in the scope. I cannot compile it. (Although it would work with vanilla JS)
Is there a way to treat variable name shop in the loop as an expression and create a dynamic class based on it?
purchasable?noImplicitAnycompiler option enabled?class BaseShop { } interface ShopContructor { new (index: number): BaseShop; } interface Window { [shop: string]: ShopContructor; }