Skip to content

Commit

Permalink
Merge pull request #511 from lrypto/patch-1
Browse files Browse the repository at this point in the history
Update typescript.md
  • Loading branch information
mweststrate committed Feb 3, 2020
2 parents 3b0fdcb + 167a402 commit fb0f3a0
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 fb0f3a0

Please sign in to comment.