Skip to content

Commit

Permalink
Merge 167a402 into ef8990b
Browse files Browse the repository at this point in the history
  • Loading branch information
elrypto committed Jan 15, 2020
2 parents ef8990b + 167a402 commit 3d11f1e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion docs/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ This will generate the error:
The type 'readonly Todo[]' is 'readonly' and cannot be assigned to the mutable type '{ done: boolean; }[]'
```

The reason for this error is that we assing our read only, immutable array to our draft, which expects a mutable type, with methods like `.push` etc etc. As far as TS is concerned, those are not exposed from our original `State`. To hint TypeScript that we want to upcast the collection here to a mutable array for draft purposes, we can use the utility `asDraft`:
The reason for this error is that we assign our read only, immutable array to our draft, which expects a mutable type, with methods like `.push` etc etc. As far as TS is concerned, those are not exposed from our original `State`. To hint TypeScript that we want to upcast the collection here to a mutable array for draft purposes, we can use the utility `asDraft`:

`draft.finishedTodos = castDraft(state.unfinishedTodos)` will make the error disappear.

Expand Down

0 comments on commit 3d11f1e

Please sign in to comment.