У меня есть класс супер , который является родительским ( Entity) для многих подкласса ( Customer, Product, ProductCategory...)
Я хочу динамически клонировать объект, который содержит различные подобъекты в Typescript.
В примере: у Customerкоторого есть разные, у Productкого естьProductCategory
var cust:Customer = new Customer ();
cust.name = "someName";
cust.products.push(new Product(someId1));
cust.products.push(new Product(someId2));
Для клонирования всего дерева объекта я создал функцию в Entity
public clone():any {
var cloneObj = new this.constructor();
for (var attribut in this) {
if(typeof this[attribut] === "object"){
cloneObj[attribut] = this.clone();
} else {
cloneObj[attribut] = this[attribut];
}
}
return cloneObj;
}
newПоднимается следующее сообщение об ошибке , когда он transpiled в JavaScript:error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
Хотя скрипт работает, я хотел бы избавиться от трансплантированной ошибки