Skip to content
Myr

chore: fix some comments (#1122)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by clonemycode · committed by GitHub · parent 062210e · Browse files · 3 files+3 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: clonemycode <clonecode@aliyun.com>

Diff stats

3 files+3 added−3 removed

  • tests:+2 added−2 removed
  • other:+1 added−1 removed

3 files+3 added−3 removed

modified:__tests__/base.js+1 added-1 removed
488 unmodified lines
489 expect(base.get(key)).toEqual(value)490 expect(nextState.get(key)).toEqual(true)491 })492493 it("state stays the same if the the same item is assigned by key", () => {493 it("state stays the same if the same item is assigned by key", () => {494 const nextState = produce(baseState, s => {495 s.aMap.set("jediTotal", 42)496 })497 expect(nextState).toBe(baseState)
1959 unmodified lines
modified:__tests__/produce.ts+1 added-1 removed
734 unmodified lines
735 const n = f(base as ROState)736 assert(n, _ as State)737 }738 {739 // explictly use generic739 // explicitly use generic740 const f = produce<ROState>(draft => {741 draft.count++742 })743 const n = f(base as ROState)
17 unmodified lines
modified:website/docs/typescript.mdx+1 added-1 removed
107 unmodified lines
108Note that we did wrap the `Todo` type of the `draft` argument with `Draft`, because `Todo` is a readonly type. For non-readonly types this isn't needed.109110For 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`.111112In 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.112In 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.113114This 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>`:115116```typescript
95 unmodified lines