redux-persist
redux-persist copied to clipboard
[Typescript BUG] _persist is missing in type State but required in PersistPartial
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch [email protected] for the project I'm working on.
TLDR; when passing initialState to a persisted reducer, typescript expects a _persist key to be defined in your initial state (which it doesn't need to be).
Typescript Error: Type 'XState' is not assignable to type 'XState & PersistPartial'. Property '_persist' is missing in type 'XState' but required in type 'PersistPartial'
Without it, I was getting a typescript issue when passing initial state into a persisted reducer. This is because the persisted reducer was typed as Reducer<WorkoutNowState & PersistPartial, AnyAction>, and PersistPartial requires a _persist key to be defined in the reducer, which I obviously didn't want to define in the initial state.
Looks like this issue was solved in 2018 here, but seems to have crept back in: https://github.com/rt2zz/redux-persist/pull/725
Here is the diff that solved my problem:
diff --git a/node_modules/redux-persist/types/persistReducer.d.ts b/node_modules/redux-persist/types/persistReducer.d.ts
index d56b212..ff7e877 100644
--- a/node_modules/redux-persist/types/persistReducer.d.ts
+++ b/node_modules/redux-persist/types/persistReducer.d.ts
@@ -3,7 +3,7 @@ declare module "redux-persist/es/persistReducer" {
import { PersistState, PersistConfig } from "redux-persist/es/types";
interface PersistPartial {
- _persist: PersistState;
+ _persist?: PersistState;
}
/**
This issue body was partially generated by patch-package.
Same Issue #1170 And #1170 is merged, but not release..