This does not answer the question directly, but I want to tell you how I do it. In typescript I usually make classes for my objects, and constructors for deep copying objects of the same type. You can then pass an object of the same type, or the attributes directly using two constructors.
export class MyObject {
myAttribute:string;
otherAttributes:Array<string>;
constructor();
constructor(myAttributeOrObj?:MyObject|string);
constructor(myAttributeOrObj?:any, otherAttributes:Array<string>){
if(myAttributeOrObj && myAttributeOrObj.myAttribute){
this.myAttribute = myAttributeOrObj.myAttribute;
this.createOtherAttributes(myAttributeOrObj.otherAttributes);
}else{
this.myAttribute=myAttributeOrObj;
this.createOtherAttributes(otherAttributes);
}
}
createOtherAttributes(arr){
this.otherAttributes = [];
for(var i = 0; i< arr.length; i++){
this.otherAttributes.push(arr[i]);
}
}
}
This method may create overhead compared to using existing libraries, but with this method you have full control of your objects, types and know you have made a deep copy instead of a shallow one.
More information about constructor overload can be found in this question Constructor overload in TypeScript