Skip to content

TypeScript Types

Redux Remember exports the following TypeScript types for better type safety in your application.

Storage driver interface for implementing custom storage solutions.

interface Driver {
setItem(key: string, value: any): void | Promise<void>;
getItem(key: string): any | Promise<any>;
}

See: Custom Storage Driver for complete implementation examples.

Configuration options for rememberEnhancer.

interface Options {
prefix?: string;
serialize?: (state: any, key: string) => string;
unserialize?: (state: string, key: string) => any;
migrate?: (state: any) => any;
persistThrottle?: number;
persistDebounce?: number;
persistWholeStore?: boolean;
errorHandler?: (error: PersistError | RehydrateError | MigrateError) => void;
initActionType?: string;
}

The errorHandler receives PersistError, RehydrateError, or MigrateError instances.

See: rememberEnhancer for detailed descriptions of each option.

Tip: It is highly recommended that you use use Redux Remigrate for type-safe migrations with auto-generated version types and CLI tooling.

class PersistError extends Error {
// Thrown when persistence fails
}

Thrown when: State cannot be saved to storage (e.g., quota exceeded, storage unavailable).

class RehydrateError extends Error {
// Thrown when rehydration fails
}

Thrown when: State cannot be loaded from storage (e.g., corrupted data, parsing errors).

class MigrateError extends Error {
// Thrown when migration fails
}

Thrown when: The migrate function throws an error during state migration. When this occurs, the default store state (from reducer initial values) is used to prevent the app from crashing.

Note: Migration only runs if rehydration was successful. If rehydration fails, migration is skipped entirely.

See: Error Handling Guide for complete examples of handling these errors.