Skip to content

Commit

Permalink
feature: Improved typescript types
Browse files Browse the repository at this point in the history
The TypeScript typings of Immer have been rewritten, and support better inference now and are more accurate. The best practices are documented here: https://immerjs.github.io/immer/typescript. Please visit that page first when running into any compile errors after updating. 

The following changes have been made:

Immer can now infer the type of the `draft` for curried producers, if they are directly passed to another function / context from which the type can be inferred. So lines like these will now be strongly typed: `setTodo(produce(draft => { draft.done = true }))`, where `setTodo` is a React state updater (for example). Fixes #720.

Immer will now better respect the original types passed to a producer, and generally not wrap any returned types with `Immutable` automatically.

BREAKING CHANGE: It is no longer allowed to return `nothing` from a recipe if the target state doesn't accept `undefined`.

BREAKING CHANGE: It is no longer allowed to return arbitrary things from a recipe. Recipes should either return nothing, or something that is assignable to the original state type. This will catch mistakes with accidental returns earlier.
  • Loading branch information
mweststrate authored Mar 19, 2021
1 parent b7fcf7f commit 2c2f30e
Show file tree
Hide file tree
Showing 7 changed files with 761 additions and 231 deletions.
Loading

0 comments on commit 2c2f30e

Please sign in to comment.