मेरे पास एक सुपर क्लास है जो Entityकई उपवर्गों के लिए माता-पिता ( ) है Customer, ( Product, ProductCategory...)
मैं गतिशील रूप से एक ऑब्जेक्ट को क्लोन करने के लिए देख रहा हूं जिसमें टाइपस्क्रिप्ट में विभिन्न उप ऑब्जेक्ट शामिल हैं।
उदाहरण में: एक 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 है उगता है:error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
हालांकि स्क्रिप्ट काम करती है, मैं ट्रांसप्लेड एरर से छुटकारा पाना चाहूंगा