You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically allow 'this' return type to be applied to static class methods as well.
π Motivating Example
class Singleton {
constructor() {
if (this.constructor.name === 'Singleton') {
throw new Error("Can't instantiate the Singleton class directly")
}
const subclass = this.constructor as { __singleton_instance?: object }
if (subclass.__singleton_instance) {
throw new Error("Class can only be instantiated once")
}
subclass.__singleton_instance = this
}
public static get instance(): this {
return (this as { __singleton_instance?: object }).__singleton_instance ?? new this()
}
}
class SomeObject extends Singleton {} // No wrapper "get instance" method that explicitly returns SomeObject needed
π» Use Cases
As mentioned above.
The text was updated successfully, but these errors were encountered:
π Search Terms
static polymorphic this
β Viability Checklist
β Suggestion
Basically allow 'this' return type to be applied to static class methods as well.
π Motivating Example
π» Use Cases
As mentioned above.
The text was updated successfully, but these errors were encountered: