আমি একটি সুপার ক্লাস হয় যে আছে পিতা বা মাতা ( 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.
যদিও স্ক্রিপ্টটি কাজ করে তবে আমি স্থানান্তরিত ত্রুটি থেকে মুক্তি পেতে চাই