@@ -37,28 +37,33 @@ box with the `autoMergeLevel1` or `autoMergeLevel2` [state reconcilers](https://
3737when persisting the root reducer, or with the ` autoMergeLevel1 ` reconciler when persisting just the api reducer.
3838
3939``` ts title="redux-persist rehydration example"
40- import type { Action , PayloadAction } from ' @reduxjs/toolkit'
40+ import type { Action } from ' @reduxjs/toolkit'
4141import { createApi , fetchBaseQuery } from ' @reduxjs/toolkit/query/react'
4242import { REHYDRATE } from ' redux-persist'
4343
4444type RootState = any // normally inferred from state
4545
46- function isHydrateAction(action : Action ): action is PayloadAction <RootState > {
46+ function isHydrateAction(action : Action ): action is Action <typeof REHYDRATE > & {
47+ key: string
48+ payload: RootState
49+ err: unknown
50+ } {
4751 return action .type === REHYDRATE
4852}
4953
5054export const api = createApi ({
5155 baseQuery: fetchBaseQuery ({ baseUrl: ' /' }),
5256 // highlight-start
53- extractRehydrationInfo(action , { reducerPath }) {
57+ // to prevent circular type issues, the return type needs to be annotated as any
58+ extractRehydrationInfo(action , { reducerPath }): any {
5459 if (isHydrateAction (action )) {
55- if (( action as any ). key === ' key used with redux-persist ' ) {
56- // when persisting the api reducer
60+ // when persisting the api reducer
61+ if ( action . key === ' key used with redux-persist ' ) {
5762 return action .payload
5863 }
5964
6065 // When persisting the root reducer
61- return action .payload [reducerPath ]
66+ return action .payload [api . reducerPath ]
6267 }
6368 },
6469 // highlight-end
0 commit comments