Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix some comments #1122

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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