How to define Singleton in TypeScript

前端 未结 20 730

What is the best and most convenient way to implement a Singleton pattern for a class in TypeScript? (Both with and without lazy initialisation).

20条回答
  •  孤城傲影
    2020-11-28 20:55

    This is a typescript decorator checking if multiple instances were accidentaly created against a service class that is designed to be singleton:

    https://www.npmjs.com/package/singleton-checker

提交回复
热议问题