What is the best and most convenient way to implement a Singleton pattern for a class in TypeScript? (Both with and without lazy initialisation).
Not a pure singleton (initialization may be not lazy), but similar pattern with help of namespaces.
namespace
namespace MyClass { class _MyClass { ... } export const instance: _MyClass = new _MyClass(); }
Access to object of Singleton:
MyClass.instance