20 lines
636 B
TypeScript
20 lines
636 B
TypeScript
export { ZError } from './common/ZError.js';
|
|
|
|
/**
|
|
* 单例化一个class
|
|
* 使用方法:
|
|
* @singleton
|
|
* class Test {}
|
|
* new Test() === new Test() // returns `true`
|
|
* 也可以不使用 decorator
|
|
* const TestSingleton = singleton(Test)
|
|
* new TestSingleton() === new TestSingleton() //returns 'true'
|
|
*/
|
|
declare const SINGLETON_KEY: unique symbol;
|
|
type Singleton<T extends new (...args: any[]) => any> = T & {
|
|
[SINGLETON_KEY]: T extends new (...args: any[]) => infer I ? I : never;
|
|
};
|
|
declare const singleton: <T extends new (...args: any[]) => any>(classTarget: T) => T;
|
|
|
|
export { SINGLETON_KEY, type Singleton, singleton };
|