A derived class is allowed be created without a parent's getter or setter.
See original GitHub issueBug Report
🔎 Search Terms
class extend override getter setter accessor
🕗 Version & Regression Information
- This seems to occur on all versions on the Playground (3.9+)
⏯ Playground Link
Playground link with relevant code
💻 Code
class Parent {
public get f() { return () => {}; }
}
class Child extends Parent {
public set f(func: () => void) { }
}
const c = new Child();
c.f(); // runtime error because Child doesn't implement the getter for f
🙁 Actual behavior
Class Child
is allowed to extend class Parent
even though, by adding a setter for f
, it discards the getter for f
and therefore doesn’t implement Parent’s contract.
🙂 Expected behavior
TypeScript should emit an error because Child
is not compatible with Parent
.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to call a property of the base class if this ... - Stack Overflow
In B, accessing the property getter of the parent class A: ... Although I'm not sure if python supports calling the base class...
Read more >Class inheritance - The Modern JavaScript Tutorial
Class inheritance is a way for one class to extend another class. So we can create new functionality on top of the existing....
Read more >Kotlin Inheritance, Method Overriding, and Property Overriding
The class that inherits the features of another class is called the Child class or Derived class or Sub class, and the class...
Read more >Getters and Setters: Manage Attributes in Python
They're not inherited independently but as a whole. Therefore, when you override the getter method of a property inherited from a parent class, ......
Read more >Classes - Object-Oriented Programming in Python
When we create an object of that data type, we call it an instance of a class. ... for these allowed attributes when...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In the following code, typescript expects a boolean, however at runtime it is actually undefined.
Playground Link
I think that most would expect
Child
to inheritParent
’s getter and behave the same as the following code: Playground Linkjust being hit by this issue. The typeScript should error if the parent class has getter/setter but the child only have setter, because in most cases, people’s intention is to “inherit” the getter from the parent class.