Suppose a class adds itself to an other class as follows
bar.ts
:
import { Foo } from './foo';
export class Bar {}
Foo.prop = Bar;
And file foo.ts
export class Foo {
public static prop: any;
}
Now, if would like to use this in index.ts
import { Foo } from './foo';
console.log(Foo.prop); // -> undefined
It is undefined. It looks like that bar.ts
is not used at all (probably tree shaking). So I can fix that as follows:
import { Foo } from './foo';
import { Bar } from './bar';
new Bar(); // trick!
console.log(Foo.prop); // -> Bar
Is there a way to tell typescript to include Bar
anyway, because the solution I showed is ugly.
For completeness, here is my tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"sourceMap": true,
"noImplicitAny": false,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2017",
"outDir": "./dist",
"baseUrl": "./",
"lib": ["es2017", "dom", "dom.iterable"]
},
"exclude": ["node_modules", "**/*.spec.ts", "dist"]
}