Skip to content

Commit

Permalink
chore: fix some comments
Browse files Browse the repository at this point in the history
Signed-off-by: clonemycode <[email protected]>
  • Loading branch information
clonemycode committed May 1, 2024
1 parent e2d222b commit 8a3ada4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion __tests__/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ function runBaseTest(name, autoFreeze, useStrictShallowCopy, useListener) {
expect(nextState.get(key)).toEqual(true)
})

it("state stays the same if the the same item is assigned by key", () => {
it("state stays the same if the same item is assigned by key", () => {
const nextState = produce(baseState, s => {
s.aMap.set("jediTotal", 42)
})
Expand Down
2 changes: 1 addition & 1 deletion __tests__/produce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ it("infers curried", () => {
assert(n, _ as State)
}
{
// explictly use generic
// explicitly use generic
const f = produce<ROState>(draft => {
draft.count++
})
Expand Down
2 changes: 1 addition & 1 deletion website/docs/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Note that we did wrap the `Todo` type of the `draft` argument with `Draft`, beca

For the returned curried function, `toggler`, We will _narrow_ the _input_ type to `Immutable<Todo>`, so that even though `Todo` is a mutable type, we will still accept an immutable todo as input argument to `toggler`.

In contrast, Immer will _widen_ the _output_ type of the curried function to `Writable<Todo>`, to make sure it's output state is also assignable to variables that are not explictly typed to be immutable.
In contrast, Immer will _widen_ the _output_ type of the curried function to `Writable<Todo>`, to make sure it's output state is also assignable to variables that are not explicitly typed to be immutable.

This type narrowing / widening behavior might be unwelcome, maybe even for the simple reason that it results in quite noisy types. So we recommend to specify the generic state type for curried producers instead, in cases where it cannot be inferred directly, like `toggler` above. By doing so the automatic output widening / input narrowing will be skipped. However, the `draft` argument itself will still be inferred to be a writable `Draft<Todo>`:

Expand Down

0 comments on commit 8a3ada4

Please sign in to comment.