Do you want to know about the Typescript override keyword? In this Typescript tutorial, I will show you how to use the override Keyword in Typescript with a complete example.
To use the ‘override’ keyword in TypeScript, declare it in a subclass method that intentionally overrides a method in its superclass. This keyword enhances code clarity and helps prevent errors by ensuring the overridden method exists and matches in the base class. For example, in a Dog class extending an Animal class, use override makeSound() in Dog to explicitly override the makeSound method in Animal.
What is the override Keyword in Typescript?
The ‘override’ keyword in TypeScript is important for developers working with class inheritance. It explicitly denotes that a method in a subclass is intended to override a method in its superclass. This explicit declaration serves two primary purposes:
- Enhanced Code Clarity: It becomes immediately clear to anyone reading the code that the method is overriding another.
- Error Prevention: The TypeScript compiler checks for the existence of the method in the base class. If the base class method is missing, renamed, or the signatures don’t match, it throws an error, thus preventing potential runtime issues.
Typescript override keyword example
Now, let us see, how to use the override keyword in Typescript with an example.
Base Class: Vehicle
First, we have a base class named Vehicle with a method startEngine.
class Vehicle {
startEngine() {
console.log("Engine started");
}
}
Derived Class: Car
Next, we create a subclass Car that extends Vehicle. In Car, we override the startEngine method using the override keyword.
class Car extends Vehicle {
override startEngine() {
console.log("Car engine started with a roar!");
}
}
In this example, the Car class overrides the startEngine method from the Vehicle class. The use of the override keyword explicitly indicates that the method in Car is intentionally overriding the method in Vehicle.
To test this code, you can create an instance of Car and call the startEngine method:
const myCar = new Car();
myCar.startEngine();
Here is the complete code:
class Vehicle {
startEngine() {
console.log("Engine started");
}
}
class Car extends Vehicle {
override startEngine() {
console.log("Car engine started with a roar!");
}
}
const myCar = new Car();
myCar.startEngine();
You can see the output in the screenshot below once I ran the code using Visual Studio Code.

Here are a few points to remember while using the Typescript override keyword.
- Always Use ‘override’ When Overriding Methods: This clarifies your intentions and leverages TypeScript’s error-checking capabilities.
- Keep Method Signatures Consistent: Ensure that the overriding method has the same signature as the method in the base class to avoid errors.
- Refactor Carefully: When changing method names or signatures in base classes, remember to update all derived classes. TypeScript’s error messages can guide you in this process.
Conclusion
I hope you got an idea of the Typescript override keyword. I have explained the override keyword in Typescript with a complete example.
You may also like:
- as Keyword in Typescript
- this Keyword in Typescript
- unique Keyword in TypeScript
- is Keyword in Typescript
- super Keyword in Typescript

Hey! I’m Bijay Kumar, founder of SPGuides.com and a Microsoft Business Applications MVP (Power Automate, Power Apps). I launched this site in 2020 because I truly enjoy working with SharePoint, Power Platform, and SharePoint Framework (SPFx), and wanted to share that passion through step-by-step tutorials, guides, and training videos. My mission is to help you learn these technologies so you can utilize SharePoint, enhance productivity, and potentially build business solutions along the way.