Override and super
Concept and syntax
override marks a member intended to replace an inherited member. noImplicitOverride requires that marker for overrides, helping detect base-class renames. super accesses the inherited implementation; a derived constructor must call super before accessing this. The marker itself does not alter dispatch.
Working example
Save each snippet separately as main.ts in a fresh directory. Compile with tsc --strict --target ES2022 --module commonjs --moduleDetection force --skipLibCheck --noEmitOnError --noImplicitOverride main.ts, then run the accepted example with node main.js. Forced module detection isolates snippet names from global declarations.
class Base {label(){return "base";}}class Child extends Base {override label(){return super.label()+"+child";}}console.log(new Child().label());Expected output:
base+childWithout the override check
Remove --noImplicitOverride from the command and compile this separate example. The child method still overrides the base method, and the output is child. The option affects checking, not dispatch.
class Base {label(){return "base";}}class Child extends Base {label(){return "child";}}console.log(new Child().label());Common mistake
Intentionally invalid; compile separately and do not execute.
class Base {label(){return "base";}}class Child extends Base {label(){return "child";}}Expected diagnostic: TS4114. With noImplicitOverride enabled the overriding method needs override. Add the marker.
Practice and recap
Rename the base method and see how override exposes the stale subclass.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Override and super — knowledge check
Check the contract, trace output, and diagnose an invalid example.
Which statement about this lesson’s concept is accurate?
What is the complete stdout, represented as a JSON string (including newline characters)?
class Base {label(){return "base";}}class Child extends Base {override label(){return super.label()+"+child";}}console.log(new Child().label());Which diagnostic and explanation match the rejected example under the lesson settings?
class Base {label(){return "base";}}class Child extends Base {label(){return "child";}}