Copier l'objet dans TypeScript
//1.Shallow copy:
let Copy = {...yourObject}
//2.Deep Copy: a. through recusive typing functionality:
let Cone = DeepCopy(yourObject);
public DeepCopy(object: any): any
{
if(object === null)
{
return null;
}
const returnObj = {};
Object.entries(object).forEach(
([key, value]) =>{
const objType = typeof value
if(objType !== "object" || value === null){
returnObj[key] = value;
}
else{
returnObj[key] = DeepCopy(value);
}
}
//b.Hardway: repeat the following expanstions for all complex types as deep as you need
let Copy = {...yourObject, yourObjsComplexProp: {...yourObject.yourObjsComplexProp}}
TheCodeTrooper