Skip to content

docs(immer): fix setPerson updater type in usage examples#3502

Merged
dbritto-dev merged 1 commit into
pmndrs:mainfrom
TheSeydiCharyyev:docs/immer-set-person-type
May 20, 2026
Merged

docs(immer): fix setPerson updater type in usage examples#3502
dbritto-dev merged 1 commit into
pmndrs:mainfrom
TheSeydiCharyyev:docs/immer-set-person-type

Conversation

@TheSeydiCharyyev

Copy link
Copy Markdown
Contributor

The setPerson action type in both usage examples of immer.md is malformed — a misplaced parenthesis puts | PersonStoreState['person'] inside the function's return type instead of making it a top-level union member.

Current:

setPerson: (
  nextPerson: (
    person: PersonStoreState['person'],
  ) => PersonStoreState['person'] | PersonStoreState['person'],
) => void

This types nextPerson as (person: P) => (P | P) — i.e. always a function, with a redundant P | P return type. But the example's own implementation handles both a value and an updater function:

setPerson: (nextPerson) =>
  set((state) => ({
    person:
      typeof nextPerson === 'function'
        ? nextPerson(state.person)
        : nextPerson,
  })),

With the current type the : nextPerson branch is unreachable.

The intended type is a value-or-updater union — the same pattern already used correctly by setAge in create.md:

nextAge:
  | AgeStoreState['age']
  | ((currentAge: AgeStoreState['age']) => AgeStoreState['age']),

Diff

  setPerson: (
-   nextPerson: (
-     person: PersonStoreState['person'],
-   ) => PersonStoreState['person'] | PersonStoreState['person'],
+   nextPerson:
+     | PersonStoreState['person']
+     | ((person: PersonStoreState['person']) => PersonStoreState['person']),
  ) => void

Applied to both usage examples (the plain createStore example and the immer example). Docs-only change — no changeset needed.

@vercel

vercel Bot commented May 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
zustand-demo Ready Ready Preview, Comment May 20, 2026 10:08am

Request Review

@codesandbox-ci

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@pkg-pr-new

pkg-pr-new Bot commented May 20, 2026

Copy link
Copy Markdown

commit: 9907854

@dbritto-dev dbritto-dev merged commit 2ce8226 into pmndrs:main May 20, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants