CodePark/ questions / Inheritance, overriding & Liskov
START PRACTICINGPRACTICE
Backend question · Object-oriented programming › Inheritance, overriding & Liskov

noImplicitOverride is on. A teammate renames BaseHandler.handle() to process() but forgets the subclass. What happens?

class BaseHandler {
  process(job: Job): void { /* was handle() */ }
}
class AuditHandler extends BaseHandler {
  override handle(job: Job): void { /* audit, then work */ }
}
A compile error: handle has an override modifier but is not declared in the base class

It is a compile error (TS4113): "This member cannot have an 'override' modifier because it is not declared in the base class". override tells the compiler "this method must replace a parent method". With noImplicitOverride, every real override must use it, so renames can't break things silently.

"It compiles, and
AuditHandler.handle is simply a new method" is what happens without override. Then the audit logic quietly stops running.