Reputation: 59365
I remember being able to provide an interface for a abstract class, something like this, but I can't find that code online anywhere. I am I unable to do it here:
interface AbstractParent {
staticMember: () => boolean
}
abstract class AbstractParent {
static example() {
return this.staticMember()
}
}
class Utilize extends AbstractParent {
static staticMember() {
return true
}
}
console.log(Utilize.example())
Is it possible to have an abstract class require a static method?
Upvotes: 2
Views: 265
Reputation: 4138
You can also try replacing this.staticMember()
with Utilize.staticMember()
: Playground
Ideally, you want to use static abstract staticMember
. But unfortunetly, it's not yet supported and doesn't seem like there's a good way to implement this.
Check our these discussions:
static abstract
methods and propertiesUpvotes: 2
Reputation: 59365
This works without error, but does not ensure that Utilize
implements a staticMember
method.
abstract class AbstractParent {
static staticMember: () => boolean
static example() {
return this.staticMember()
}
}
class Utilize extends AbstractParent {
static staticMember() {
return true
}
}
console.log(Utilize.example())
Upvotes: 0