a library to speed up the development of Fivem scripts and frameworks
fivem-ts - Documentation v0.7.5 • Docs
fivem-ts - Documentation v0.7.5 / Shared / Singleton
Singleton<
T>(constructor): (…args) =>(Anonymous class)<T> &T
A decorator that ensures a class follows the Singleton pattern.
The @Singleton decorator enforces that a class can have only one instance. When a class is decorated with
@Singleton, any subsequent instantiations will return the same instance rather than creating a new one.
This is useful for scenarios where you want to ensure a single point of control or a global state.
• T extends (…args) => object
constructor type of the class being decorated.
• constructor: T
The class constructor to decorate.
(…args) => (Anonymous class)<T> & T
A new class that extends the original class, ensuring only one instance is created.
@Singleton
class Configuration {
    public settings: any;
    constructor() {
        this.settings = { theme: 'dark' };
    }
}
const instance1 = new Configuration();
const instance2 = new Configuration();
console.log(instance1 === instance2); // true