@@ -37,28 +37,33 @@ box with the `autoMergeLevel1` or `autoMergeLevel2` [state reconcilers](https://
37
37
when persisting the root reducer, or with the ` autoMergeLevel1 ` reconciler when persisting just the api reducer.
38
38
39
39
``` ts title="redux-persist rehydration example"
40
- import type { Action , PayloadAction } from ' @reduxjs/toolkit'
40
+ import type { Action } from ' @reduxjs/toolkit'
41
41
import { createApi , fetchBaseQuery } from ' @reduxjs/toolkit/query/react'
42
42
import { REHYDRATE } from ' redux-persist'
43
43
44
44
type RootState = any // normally inferred from state
45
45
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
+ } {
47
51
return action .type === REHYDRATE
48
52
}
49
53
50
54
export const api = createApi ({
51
55
baseQuery: fetchBaseQuery ({ baseUrl: ' /' }),
52
56
// 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 {
54
59
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 ' ) {
57
62
return action .payload
58
63
}
59
64
60
65
// When persisting the root reducer
61
- return action .payload [reducerPath ]
66
+ return action .payload [api . reducerPath ]
62
67
}
63
68
},
64
69
// highlight-end
0 commit comments