I want to create a new instance of the Child class from the Base class .
This is a bit complicated, but I will try to explain.
Here is an example:
class Base(){
constructor(){}
clone(){
}
}
class Child extends Base(){}
var bar = new Child();
var cloned = bar.clone();
clone instanceof Child
So. In this example, I want to clone my instance bar, which must be an instanceChild
Well. I am trying to follow in a method Bar.clone:
clone(){
return new this.constructor()
}
... And this works in compiled code, but I have typescript error:
error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
Any ideas how I can handle this?
Thank. Hope this helps some1 :)
user474470
source
share