question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

redux-persist on typescript

See original GitHub issue

Anyone here can give me a simple implementations of a redux-persist on typescript? I always got error like this when i try to create persistor

Argument of type 'Store<{ readonly [$CombinedState]?: undefined; } & { todo: TodoState; } & PersistPartial, TodoActionTypes>' is not assignable to parameter of type 'Store<any, AnyAction>'. Types of property 'dispatch' are incompatible. Type 'Dispatch<TodoActionTypes>' is not assignable to type 'Dispatch<AnyAction>'. Type 'AnyAction' is not assignable to type 'TodoActionTypes'. Type 'AnyAction' is not assignable to type 'DeleteTodoAction'.

This my code

Thanks

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:27
  • Comments:20

github_iconTop GitHub Comments

43reactions
chrispayntercommented, Feb 25, 2020

My fix may not be so relevant, but this question at least led me to a solution so I’ll post it in the off chance someone with the same problem as I comes across this.

I just had to type persistReducer. For example:

persistReducer<RootState>(persistConfig, rootReducer());
20reactions
TimCrookercommented, Feb 9, 2022

if you are using redux/toolkit and are getting this error or losing typing on your selectors then use the following configuration:

store.ts

const rootReducer = combineReducers({
	user: userReducer,
})

const persistedReducer = persistReducer(
	persistConfig,
	rootReducer
) as typeof rootReducer

export const store = configureStore({
	reducer: persistedReducer,
	middleware: (getDefaultMiddleware) =>
		getDefaultMiddleware({
			serializableCheck: false,
		})
})

export const persistor = persistStore(store)

export type AppDispatch = typeof store.dispatch

export type RootState = ReturnType<typeof store.getState>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Persisting your React application state with Redux and ...
How to manage and save your application state to any kind of storage using redux-persist. If you've ever developed a React application and ......
Read more >
How to add redux-persist to typescript project? - Stack Overflow
I'm trying to add redux-persist to my React project (using typescript). But I have some trouble. Compiling falls with following error:
Read more >
How To Clear a Redux Toolkit State That's Using redux-persist ...
Using redux-persist to persist and rehydrate state if the user closes, or refreshes / uses the navigation buttons on their browser. Generating a...
Read more >
redux-persist migrations in TypeScript with a little help from ...
redux -persist migrations in TypeScript with a little help from patch-package - persistMigration.ts. ... import { createMigrate } from 'redux-persist';.
Read more >
redux-persist persistReducer TypeScript Examples
redux -persist#persistReducer TypeScript Examples ... The following examples show how to use redux-persist.persistReducer. You can vote up the ones you like or ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found