TS4115
This parameter property must have an 'override' modifier because it overrides a member in base class 'MovingAverage'.
Broken Code ❌
class MovingAverage {
constructor(protected readonly length: number) {}
}
class MyStrategy extends MovingAverage {
// TS4115
constructor(protected readonly length: number) {
super(length);
}
}This error occurs because you're using a parameter property (a property declared directly in the constructor) to override a property from the base class, but you haven't marked it with the override modifier.
Fixed Code ✔️
When using parameter properties to override a property from a parent class, you must explicitly use the override keyword to make your intent clear to the compiler. This ensures safe refactoring and helps catch accidental mismatches in the base class.
class MovingAverage {
constructor(protected readonly length: number) {}
}
class MyStrategy extends MovingAverage {
constructor(protected override readonly length: number) {
super(length);
}
}