Comments (2)
No, the design of produce
is to always have the same input and output type; it is intended to mutate an existing structure, not a mapping function that produces a new kind of object. So in this case you indeed have to cast or make the input type wide enough to also capture the output.
from immer.
I'm using this method as for now:
const objWithoutId: ObjWithoutId = getSomeObj();
const objWithId = produce(objWithoutId, (draft: Draft<ObjWithId>) => {
draft.id = 5;
}) as ObjWithId;
But maybe there is a better way, without as
from immer.
Related Issues (20)
- Immer problem HOT 1
- When ImmerJS processes objects containing Symbol keys, the Symbols become Proxies. HOT 1
- Property ... is missing in type WritableDraft<...> but required in type ... HOT 1
- "Maximum call stack exceeded" with circular references HOT 5
- Use Immer Reducer to create Composite Object HOT 5
- type WritableDraft is not exported anywhere in dist, this causes build type declaration files with Draft finally fall back to raw and causing the type declaration exceeds max token length
- Array update speed HOT 1
- Options for older browser support in v10 (or continuing to use v9 somehow?) HOT 4
- Object values of a `Map` are not frozen anymore HOT 2
- Can immer.js can be used for future mutations? HOT 3
- Maybe update docs
- Configure rollup
- Typescript: Cannot assign immutable state from payload to immutable writable draft HOT 2
- Unable to pass generic to produce for dynamic typing
- how to modify data with unknown path HOT 3
- Proper Way To Get Current State With Immer ? HOT 4
- Issue to index generic record with generic key value in recipe due to draft wrapper
- support property produce hook
- Clarify the use of useCallback in documentation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from immer.