1.0.4 • Published 10 months ago

singleton-factory v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

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);
1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago