Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท tsconfig: Type Checking Options

TypeScript noImplicitOverride option

Reference for noImplicitOverride: requiring the override modifier on overriding class members, errors TS4114 and TS4113, and safe refactoring of base classes.

When a subclass defines a method with the same name as one in its base class, it silently replaces it. If someone later renames the base method, the subclass method becomes an unrelated new method and the "override" quietly stops working.

The override modifier states the intent: this member must exist in the base class. noImplicitOverride makes the modifier mandatory. With it on, any member that overrides a base member without override is an error. The modifier itself is always checked, even without the option. The option is not part of strict.

TypeScript
class Dog extends Animal {
  override speak(): string { return "woof"; }
}

Try it

TypeScript override catches a renamed base method

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

TypeScript override on a member the base lacks

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Syntax

JSON
{ "compilerOptions": { "noImplicitOverride": true } }
Part Description
Value true or false. Default: false. Not included in strict. Added in TypeScript 4.3.
Missing modifier TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'Base'. (only with the option on).
Wrong modifier TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'Base'. (always).
Applies to Methods, properties, accessors and parameter properties in classes with an extends clause.

Usage notes

  • Abstract members implemented in a subclass do not require override under the option (the modifier is still allowed there); implementing an interface member does not need it either, because implements is not inheritance.
  • Parameter properties can be marked: constructor(override readonly name: string).
  • It is erased. override produces no JavaScript, like a type annotation.
  • Refactoring safety is the main benefit: renaming or removing a base member turns every stale override into an error.
  • Order of modifiers: public override, protected override async; override comes after the accessibility modifier and static.
  • useDefineForClassFields interacts with overridden fields; redeclaring a base property in a subclass without initializer can reset it to undefined, and override at least makes the redeclaration explicit.