import type { StateCreator, StoreMutatorIdentifier } from 'zustand/vanilla'; export interface StateStorage { getItem: (name: string) => string | null | Promise; setItem: (name: string, value: string) => R; removeItem: (name: string) => R; } export type StorageValue = { state: S; version?: number; }; export interface PersistStorage { getItem: (name: string) => StorageValue | null | Promise | null>; setItem: (name: string, value: StorageValue) => R; removeItem: (name: string) => R; } type JsonStorageOptions = { reviver?: (key: string, value: unknown) => unknown; replacer?: (key: string, value: unknown) => unknown; }; export declare function createJSONStorage(getStorage: () => StateStorage, options?: JsonStorageOptions): PersistStorage | undefined; export interface PersistOptions { /** Name of the storage (must be unique) */ name: string; /** * Use a custom persist storage. * * Combining `createJSONStorage` helps creating a persist storage * with JSON.parse and JSON.stringify. * * @default createJSONStorage(() => localStorage) */ storage?: PersistStorage | undefined; /** * Filter the persisted value. * * @params state The state's value */ partialize?: (state: S) => PersistedState; /** * A function returning another (optional) function. * The main function will be called before the state rehydration. * The returned function will be called after the state rehydration or when an error occurred. */ onRehydrateStorage?: (state: S) => ((state?: S, error?: unknown) => void) | void; /** * If the stored state's version mismatch the one specified here, the storage will not be used. * This is useful when adding a breaking change to your store. */ version?: number; /** * A function to perform persisted state migration. * This function will be called when persisted state versions mismatch with the one specified here. */ migrate?: (persistedState: unknown, version: number) => PersistedState | Promise; /** * A function to perform custom hydration merges when combining the stored state with the current one. * By default, this function does a shallow merge. */ merge?: (persistedState: unknown, currentState: S) => S; /** * An optional boolean that will prevent the persist middleware from triggering hydration on initialization, * This allows you to call `rehydrate()` at a specific point in your apps rendering life-cycle. * * This is useful in SSR application. * * @default false */ skipHydration?: boolean; } type PersistListener = (state: S) => void; type StorePersist = S extends { getState: () => infer T; setState: { (...args: infer Sa1): infer Sr1; (...args: infer Sa2): infer Sr2; }; } ? { setState(...args: Sa1): Sr1 | Pr; setState(...args: Sa2): Sr2 | Pr; persist: { setOptions: (options: Partial>) => void; clearStorage: () => void; rehydrate: () => Promise | void; hasHydrated: () => boolean; onHydrate: (fn: PersistListener) => () => void; onFinishHydration: (fn: PersistListener) => () => void; getOptions: () => Partial>; }; } : never; type Persist = (initializer: StateCreator, options: PersistOptions) => StateCreator; declare module '../vanilla.mjs' { interface StoreMutators { 'zustand/persist': WithPersist; } } type Write = Omit & U; type WithPersist = Write>; export declare const persist: Persist; export {};