I want to copy an object by changing only one property. Without a thread, I could do this using the object distribution operator as follows:
class Point { x: number = 10; y: number = 10; } const p1 = new Point(); const p2 = {...p1, y: 5};
But when I add type annotations to p1 and p2 as follows:
const p1 = new Point(); const p2 = {...p1, y: 5};
I get the following error:
11: const p2:Point = {...p1, y: 5}; ^^^^^^^^^^^^^ object literal. This type is incompatible with 11: const p2:Point = {...p1, y: 5}; ^^^^^ Point
How can I achieve this type of operation in a safe way in a thread?
As an example, in Elm, I can do this:
p2 = { p1 | y = 5 }
There should be some equivalent in the stream.
source share