Skip to content
Myr

Update readme with note on new mapped Draft type.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kenneth Powers · committed by Kenneth Powers · parent 673db94 · Browse files · 1 file+24 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+24 added−0 removed

  • other:+24 added−0 removed

1 file+24 added−0 removed

modified:readme.md+24 added
287 unmodified lines
288## TypeScript or Flow289290The Immer package ships with type definitions inside the package, which should be picked up by TypeScript and Flow out of the box and without further configuration.291292The TypeScript typings automatically remove `readonly` modifiers from your draft types and return a value that matches your original type. See this practical example:293294```ts295import produce from 'immer';296297interface State {298 readonly x: number;299}300301// `x` cannot be modified here302const state: State = {303 x: 0;304};305306const newState = produce<State>(draft => {307 // `x` can be modified here308 draft.x++;309});310311// `newState.x` cannot be modified here312```313314This ensures that the only place you can modify your state is in your produce callbacks.315316## Immer on older JavaScript environments?317318By default `produce` tries to use proxies for optimal performance. However, on older JavaScript engines `Proxy` is not available. For example, when running Microsoft Internet Explorer or React Native on Android. In such cases Immer will fallback to an ES5 compatible implementation which works identical, but is a bit slower.319
132 unmodified lines