Skip to content

docs(react): add Action constraint to redux middleware signature#3492

Merged
dbritto-dev merged 2 commits into
pmndrs:mainfrom
TheSeydiCharyyev:docs/redux-action-constraint
May 20, 2026
Merged

docs(react): add Action constraint to redux middleware signature#3492
dbritto-dev merged 2 commits into
pmndrs:mainfrom
TheSeydiCharyyev:docs/redux-action-constraint

Conversation

@TheSeydiCharyyev
Copy link
Copy Markdown
Contributor

The redux middleware signature in the reference docs is missing the Action constraint that's present in src/middleware/redux.ts:

// src/middleware/redux.ts
type Action = { type: string }

type Redux = <
  T,
  A extends Action,    // ← constraint
  Cms extends [StoreMutatorIdentifier, unknown][] = [],
>(
  reducer: (state: T, action: A) => T,
  initialState: T,
) => StateCreator<Write<T, ReduxState<A>>, Cms, [['zustand/redux', A]]>

Without the constraint, the docs allow A to be any type. With the constraint, TypeScript enforces that action.type is accessible — which is the whole point of the redux pattern (action discriminator).

Diff

- redux<T, A>(reducerFn: (state: T, action: A) => T, initialState: T): StateCreator<T & { dispatch: (action: A) => A }, [['zustand/redux', A]], []>
+ redux<T, A extends { type: string }>(reducerFn: (state: T, action: A) => T, initialState: T): StateCreator<T & { dispatch: (action: A) => A }, [['zustand/redux', A]], []>

Single change: <T, A><T, A extends { type: string }>.

This is part of an ongoing pass over the reference docs to align signatures with source — see #3487, #3489, #3491.

Docs-only — no changeset needed.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 10, 2026

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

Project Deployment Actions Updated (UTC)
zustand-demo Ready Ready Preview, Comment May 19, 2026 11:48am

Request Review

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci Bot commented May 10, 2026

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
Copy link
Copy Markdown

pkg-pr-new Bot commented May 10, 2026

commit: a7228ad

@dbritto-dev dbritto-dev merged commit fd8c601 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