Im authoring a TS library, and would like to export an instance of a class, I intend for it be used as singleton in the consuming application.
Right now I have the following structure:
index.ts
export { Foo } from './my-class';
foo.ts
export class Foo {
functionA() {}
}
I'm then building into UMD format using webpack and babel, and in another application (Angular), I am able to import in my class, instantiate it and use it accordingly.
import { Foo } from 'foo';
private foo = new Foo();
const x = foo.functionA();
Is there a way to return an instantiated instance of my class or am I thinking about this the wrong way?
So instead of having to do new Foo()
, the imported Foo would actually already be an instance?
Thanks
UPDATE I should have mentioned, I am exporting other things such as interfaces, so I don't think a default class export would be the right way to go correct? - see here