1.0.4 • Published 3 years ago

singleton-factory v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years 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

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago