'Importing a typescript file without using any of the exports
I'm pretty new to TypeScript and I have a main.tc where I import items.tc, which contains and exports some item classes, and also adds the class types to an array from itemManager.tc. The problem is that they only get added to the array if I use atleast 1 export from items.tc in some way in main.tc, even just logging an export works.
Here is some shortened versions of my files:
main.tc
import * as Items from "./item";
import * as ItemManager from "./itemManager";
console.log(ItemManager.list) //List is empty
items.tc
import * as ItemManager from "./itemManager";
export class Item1
{
constructor()
{
}
}
ItemManager.list.push(typeof Item1);
itemManager.tc
export const list = [];
If I added console.log(Items.Item1) to my main.tc, ItemManger.list will contain all the items, but doing that is not ideal. Is there a way to make sure an imported file gets run? or am I supposed to use something else than importing?
I'm using webpack to compile it to a single .js file, I don't know if that changes anything.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
