immer
immer copied to clipboard
Omit readonly props from writable draft
🚀 Feature Proposal
Improving immer WritableDraft type
Motivation
User can assign value to readonly property in draft function. He will get runtime error, but he won't get type error.
Can this be solved in user-land code?
Yes, it can be solved in user-land code. But it would be great to have this feature on board.
Example
Example on codesandbox
You can find the magic in ./utility-types.ts. It is not so easy to omit readable props from type.
In principle the point of Immer is to "modify" immutable properties, so I think I'm missing the problem you're running into here. Also it seems that you are hiding the props, so they're not even readable anymore?
Ok, got it. Yes, you are right, I need to improve the logic so they can be readable. Anyway, I see what you mean, it's better to place wrap hook in user-land code.