You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a subclass overrides a setter of the parent but not it's getter any call to the getter will result in undefined.
But there is no compiler error, even though strict checks are activated,
So during development it seems like the getter is accessible, while at runtime it is not.
🔎 Search Terms
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about setter overide
classVehicel{protected_wheels: number=4;publicgetwheels(): number{returnthis._wheels;}publicsetwheels(value: number){this._wheels=value;}}classMotorcycleextendsVehicel{constructor(){super()this._wheels=2}publicoverridesetwheels(value: number){if(value>3){console.log("More than 3 wheels? This is no motorcycle.")return;}this._wheels=value}}vara=newMotorcycle()varb=newVehicel()console.log(`The Vehicel has ${b.wheels} wheels`)console.log(`The Motorcycle has ${a.wheels} wheels`)// wheels is undefined here
🙁 Actual behavior
Using the getter is possible without warning/error and returns undefined
🙂 Expected behavior
To ensure type safety, the developer should receive a warning/error when he tries to use a getter, which is undefined as a result of overriding the setter. Alternatively the developer should receive an error on the subclass stating Missing Override for getter xyz, due to setter override being declared.
The text was updated successfully, but these errors were encountered:
Bug Report
When a subclass overrides a
setter
of the parent but not it'sgetter
any call to the getter will result inundefined
.But there is no compiler error, even though strict checks are activated,
So during development it seems like the
getter
is accessible, while at runtime it is not.🔎 Search Terms
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Using the getter is possible without warning/error and returns
undefined
🙂 Expected behavior
To ensure type safety, the developer should receive a warning/error when he tries to use a getter, which is undefined as a result of overriding the setter. Alternatively the developer should receive an error on the subclass stating
Missing Override for getter xyz, due to setter override being declared.
The text was updated successfully, but these errors were encountered: