Skip to content

docs(persist): add U=T default to persist middleware signature#3493

Merged
dbritto-dev merged 1 commit into
pmndrs:mainfrom
TheSeydiCharyyev:docs/persist-u-default
May 10, 2026
Merged

docs(persist): add U=T default to persist middleware signature#3493
dbritto-dev merged 1 commit into
pmndrs:mainfrom
TheSeydiCharyyev:docs/persist-u-default

Conversation

@TheSeydiCharyyev
Copy link
Copy Markdown
Contributor

The persist middleware signature in the reference docs is missing the U = T default that's present in src/middleware/persist.ts:

// src/middleware/persist.ts
type Persist = <
  T,
  Mps extends [StoreMutatorIdentifier, unknown][] = [],
  Mcs extends [StoreMutatorIdentifier, unknown][] = [],
  U = T,    // ← default
>(
  initializer: StateCreator<T, [...Mps, ['zustand/persist', unknown]], Mcs>,
  options: PersistOptions<T, U>,
) => StateCreator<T, Mps, [['zustand/persist', U], ...Mcs]>

Without the default, callers must always specify both generics. With U = T, the default case (where the persisted shape matches the full state — i.e. no partialize) lets users write persist<MyStore>(...) instead of persist<MyStore, MyStore>(...).

Diff

- persist<T, U>(stateCreatorFn: StateCreator<T, [], []>, persistOptions: PersistOptions<T, U>): StateCreator<T, [['zustand/persist', U]], []>
+ persist<T, U = T>(stateCreatorFn: StateCreator<T, [], []>, persistOptions: PersistOptions<T, U>): StateCreator<T, [['zustand/persist', U]], []>

Single change: <T, U><T, U = T>.

Continuing the reference-docs alignment pass — see #3487, #3489, #3491, #3492.

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 10, 2026 4:36am

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

pkg-pr-new Bot commented May 10, 2026

commit: cceb5d6

@dai-shi dai-shi requested a review from dbritto-dev May 10, 2026 14:06
@dbritto-dev dbritto-dev merged commit f631347 into pmndrs:main May 10, 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