immer icon indicating copy to clipboard operation
immer copied to clipboard

Omit readonly props from writable draft

Open deviant310 opened this issue 2 years ago • 2 comments

🚀 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.

deviant310 avatar Jul 27 '23 13:07 deviant310

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?

mweststrate avatar Aug 14 '23 11:08 mweststrate

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.

deviant310 avatar Aug 14 '23 14:08 deviant310