Back to Blog
TypeScriptoverrideClassesInheritance

TypeScript override Keyword Guide

Master the TypeScript override keyword for explicit method overriding and safer inheritance patterns.

B
Bootspring Team
Engineering
November 27, 2019
6 min read

The override keyword explicitly marks methods that override base class methods. Here's how to use it safely.

Basic Usage

Loading code block...

Enable noImplicitOverride

Loading code block...
Loading code block...

Catching Refactoring Errors

Loading code block...

Abstract Methods

Loading code block...

Protected Methods

Loading code block...

Accessors

Loading code block...

Constructor Patterns

Loading code block...

Multiple Inheritance Levels

Loading code block...

With Mixins

Loading code block...

Generic Classes

Loading code block...

Event Handlers

Loading code block...

Testing with Override

Loading code block...

Best Practices

Usage: ✓ Enable noImplicitOverride ✓ Always use override when intended ✓ Call super when needed ✓ Match signature exactly Benefits: ✓ Catches refactoring errors ✓ Documents intent clearly ✓ Prevents accidental overrides ✓ IDE support and autocomplete Patterns: ✓ Template method pattern ✓ Hook methods ✓ Testing with mocks ✓ Framework extensions Avoid: ✗ Overriding without super when needed ✗ Changing method semantics ✗ Deep inheritance hierarchies ✗ Overriding to do nothing

Conclusion

The override keyword makes method overriding explicit and catches errors when base methods are renamed or removed. Enable noImplicitOverride in your tsconfig for the best experience. Use it consistently when extending classes to maintain a clear inheritance hierarchy and prevent subtle bugs during refactoring.

Share this article

Help spread the word about Bootspring

Related articles