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.
class Dog extends Animal { override speak(): string { return "woof"; } }
Try it
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.
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
{ "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
overrideunder the option (the modifier is still allowed there); implementing an interface member does not need it either, becauseimplementsis not inheritance. - Parameter properties can be marked:
constructor(override readonly name: string). - It is erased.
overrideproduces 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;overridecomes after the accessibility modifier andstatic. useDefineForClassFieldsinteracts with overridden fields; redeclaring a base property in a subclass without initializer can reset it toundefined, andoverrideat least makes the redeclaration explicit.