In one of my procedures I need to periodically reset a custom type, but I noticed that in TypeScript (and I think in JavaScript too maybe), when I assign a variable of a custom type to another variable of the same type, the assignment is made by reference and not by value.
For example this code:
type testing = {
a: string;
b: number;
};
let v1: testing = { a: "one", b: 1 };
let v2: testing = { a: "two", b: 2 };
console.log(v1);
console.log(v2);
v1 = v2;
v1.a = "Edited";
console.log(v1);
console.log(v2);
generates this output
{ a: 'one', b: 1 }
{ a: 'two', b: 2 }
{ a: 'Edited', b: 2 }
{ a: 'Edited', b: 2 }
Is there a way to assign it by value without assigning every property of the type?
(in my example I need my v2 variable to remain equals to { a: "two", b: 2 })