TypeScript’s override keyword (added in 4.3) works similarly to @Override in Java. It makes the intention clear and ensures there is actually a member in the base class with the same name. This helps with things like:
- Typos in the overriding member name
- Remember to rename members in sub classes when renaming an overridden member in a base class
class Parent {
foo() {}
}
class Child extends Parent {
override bar() {}
// ~~~ This member cannot have an 'override' modifier because it is not declared in the base class 'Parent'.
}
This change will not cause a runtime change: the override keyword is not present in the resulting JavaScript.
PiperOrigin-RevId: 391936931