Deep.patch() returning new object different from original object #139
Replies: 7 comments
-
Thanks for reaching out. I created a CodeSandbox to try to recreate the issue you describe. Since I don't have the As a side note, are you sure you're on the latest version of the library? (currently 0.11.0) |
Beta Was this translation helpful? Give feedback.
-
Thanks for your quick reply: I am checking out the sandbox now. The actor package needs some documentation though. I am using @ngneat/elf store (npm package) |
Beta Was this translation helpful? Give feedback.
-
This updated sandbox is closer to what I am doing. The output and my RESULT is showing undefined though. Hope you can help. |
Beta Was this translation helpful? Give feedback.
-
Thanks for updating the sandbox. I think the main issue I see there is that you are using a class for the Your remark about |
Beta Was this translation helpful? Give feedback.
-
I use Typescript. The use of plain JS is minimized and not encouraged in the project. Have you considered using a class-transformer to bridge the gap, for example class-transformer? Of course there are others. I will attempt to use it with the example and see what happens. |
Beta Was this translation helpful? Give feedback.
-
In my projects I use typed plain objects. Instead of creating a class, you can create an interface or type for the expected plain objects. If you need validation, you can use a library like zod that does validation and provides types at the same time. The issue is that a class instance cannot be reliably cloned, especially when it inherits from other classes. |
Beta Was this translation helpful? Give feedback.
-
I will investigate your advice. Thanks. |
Beta Was this translation helpful? Give feedback.
-
Hi
I have the following typescript domain models:
My store update function is shown below:
The function updates the store, but the update object is not the same type as IHIstoryState. Below is a screenshot of the store:
NB:
I expected patch to return the object it was given, with the updated patched state; however, in my code it seems to be literally including the [] symbols that are mandatory when patch is being used.
It seems that something is incorrect in my updatePC function. How can I correct this issue?
Cheers
Beta Was this translation helpful? Give feedback.
All reactions