The TypeScript compiler offers the noImplicitOverride
setting that, if set to true
, will enforce the override
keyword when overriding a non-abstract member. For example:
abstract class A {
public doSomething(): void {
}
}
class B extends A {
public doSomething(): void { // TS4114
}
}
Only when changing the problematic line to public override doSomething(): void {
will the compiler be satisfied. Excellent!
The same, however, does not hold when the inherited method happens to be abstract:
abstract class A {
public abstract doSomething(): void;
}
class B extends A {
public doSomething(): void { // no error
}
}
Is there any obscure way in the TS compiler options to enforce the override
keyword here, as well? Alternatively, I could not find any TypeScript-ESLint rule to enforce this, or is there any?
Answering the questions directly: no. There is no way as of TypeScript 5.3 or typescript-eslint 6.18.1 to enforce an override
keyword when implementing abstract
class methods.
If you'd like this to exist, there are a few options:
That last one is what I'd recommend if you don't want to wait another 1.5 years.