singleton-factory
v1.0.4
Published
Type-safe create singleton factory
Downloads
9
Maintainers
Readme
type-safe singleton factory
Example code:
class AnyClass {
}
export default singletonFactory(() => {
return new AnyClass();
});
With arguments example:
class AnyClass {
constructor(public name?: string) {}
}
const factory = singletonFactory((name?: string) => {
return new AnyClass(name);
});
// it's ok
factory('test');
// TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
factory(123);