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 method called by its parent class, the signature of the overridden method is ignored by the parent class. This is also the case with static classes.
In our example:
A function, type, returns a constructor, X.
Another method, make, invokes it and returns a constructed object, new X.
A subclass overrides the first function, type, and returns a different constructor, Y.
At runtime, calling the method make will create an instance of that second constructor, a new Y.
Typescript reports that the instance type should still be X.
🔎 Search Terms
subclass overrides static method called parent class
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about override
classX{}classYextendsX{}classA{staticmake(){constconstructor=this.type();returnnewconstructor()}statictype(){returnX;}}classBextendsA{statictype(){returnY;}}consta=A.make();// type of a is Xconstb=B.make();// type of b is X <== incorrectconsole.log(a.constructor.name);// outputs "X"console.log(b.constructor.name);// outputs "Y"
🙁 Actual behavior
The type set by the overridden function is lost.
🙂 Expected behavior
Same as JS, the overridden function sets the type.
The text was updated successfully, but these errors were encountered:
Bug Report
When a subclass overrides a method called by its parent class, the signature of the overridden method is ignored by the parent class. This is also the case with static classes.
In our example:
type
, returns a constructor,X
.make
, invokes it and returns a constructed object,new X
.type
, and returns a different constructor,Y
.make
will create an instance of that second constructor, anew Y
.X
.🔎 Search Terms
subclass overrides static method called parent class
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
Playground link with relevant code (static)
💻 Code
🙁 Actual behavior
The type set by the overridden function is lost.
🙂 Expected behavior
Same as JS, the overridden function sets the type.
The text was updated successfully, but these errors were encountered: