The package ships declarations and augments Pinia-React's Store options. A runtime import of the plugin loads the augmentation; a type-only import is enough in extracted configuration files. No application-wide pinia.d.ts or manual Store extension is needed.
Keep configuration inside defineStore for the best inference. State, Getter results and Action arguments/returns are available in hooks and error callbacks, including inside strategy arrays:
An editor suggests count, preferences, double, increment and the core Store members on store.. Nonexistent members and wrong Action arguments are type errors, rather than silently becoming any. The generated named aliases retain their ordinary inference. $state remains read-only.
The exported PersistenceContext<State, StoreType> describes a Store-level hook context. Its store is the complete inferred Store; its options.state() and plugin-only restoreState payload preserve State. restoreState is not a new application mutation API—use Actions and $patch in application code.
StatePath<State> suggests dot-separated plain-object paths for pick and omit:
Date are whole fields, not array indices/methods or instance-method paths.Dynamic string paths are intentionally accepted. A misspelled path can therefore compile and be ignored at runtime if it does not exist. Type completion is not strict path validation, and neither TypeScript nor payload shape validation verifies your business schema. Broad dictionary types cannot enumerate unknown runtime keys. Persisting a Date field still requires an appropriate representation; completion does not imply round-trip or reactive support.
Use PersistenceOptions<State> when only State access is needed:
The explicit State-only configuration does not know Getter/Action members inside its callbacks. It does not erase the Store's own Getter/Action inference.
For reusable configurations or helpers that already know a complete Store type, supply the second generic:
This example derives from the previously defined counter.ts. Do not annotate a Store initializer using the return type of its own not-yet-inferred definition; that creates a circular type dependency. Prefer inline inference for that case.
A factory is shared by Stores with different shapes. It cannot infer one Store's Getter or Action names:
Use global callbacks for cross-Store behavior and metadata. Put shape-specific logic in the Store's own callbacks instead of asserting a global generic Store to one particular Store type.
$hydrate / $persist are optional on the public Store type, even when persist: true. Module augmentation also applies to disabled Stores and Stores created without the plugin, so required methods would be an unsafe promise.
Do not use non-null assertions to hide missing plugin registration. Importing types enables configuration typing but does not install a runtime plugin; register one before Store creation as shown in Getting started.
| Type | Purpose |
|---|---|
StorageLike |
Synchronous getItem / setItem adapter |
Serializer |
Synchronous snapshot serializer; its input is not necessarily the full State |
PersistenceOptions<S, StoreType> |
One strategy, with State-only or complete Store callbacks |
PersistenceContext<S, StoreType> |
Store-level hydration hook context |
Persist<S, StoreType> |
Boolean, strategy or readonly strategy-array union |
PluginOptions |
Factory defaults, global callbacks, key transform and auto |
HydrateOptions |
Manual hydration's runHooks option |
StatePath<S> |
Suggested State paths, not a strict validation schema |
@pinia-react/persistedstate/next exports createCookiePersistedState, readCookieSnapshot, CookieSnapshot, CookieReader, CookieOptions and CookiePersistenceOptions. It also loads the same Store option augmentation. Cookie factory options require an explicit request snapshot, provide Cookie attribute completion, and reject a different factory storage or HttpOnly option. Inline Store callbacks retain the inference shown above. See the complete Next.js recipe.