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
The text was updated successfully, but these errors were encountered:
G-Rath
changed the title
TypeScript not enforcing the return type of optional methods defined in interfaces implemented by parents of classes?
TypeScript not enforcing the return type of optional methods defined in interfaces implemented by parents of classes
Apr 16, 2019
This is the intended behavior, though your code should have an error. implements does not cause optional methods to exist, so your base class is empty, so it's fine for your derived class to add a new method. Note that if you had any properties in your base class, you'd see an error about "implementing" the interface without actually doing anything.
The bug here is that we should have complained about the implements clause even though the class is empty
TypeScript Version: 3.5.0 (Also tried 3.4.1, 3.0.1, and 2.4.1)
Search Terms: Inheritance, interface, return type, parent, child, override, overload, abstract, optional method, optional interface, implements, extends
Code
Expected behavior:
TypeScript tells me that the return type for
Child#aMethod
is wrong.This behaviour is achieved if I add
implements Mx
on theChild
class.Actual behavior:
TypeScript tells me nothing! It feels that
Child#aMethod
is well within its rights to return a string.Playground Link: linky!
Related Issues: I didn't really find any similar looking issues?
The result is this could maybe relate to #22815
The text was updated successfully, but these errors were encountered: