File tree Expand file tree Collapse file tree 2 files changed +17
-8
lines changed
packages/toolkit/src/query Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -43,22 +43,27 @@ 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
Original file line number Diff line number Diff line change @@ -175,14 +175,18 @@ export interface CreateApiOptions<
175
175
*
176
176
* type RootState = any; // normally inferred from state
177
177
*
178
- * function isHydrateAction(action: Action): action is PayloadAction<RootState> {
179
- * return action.type === HYDRATE
178
+ * function isHydrateAction(action: Action): action is Action<typeof REHYDRATE> & {
179
+ * key: string
180
+ * payload: RootState
181
+ * err: unknown
182
+ * } {
183
+ * return action.type === REHYDRATE
180
184
* }
181
185
*
182
186
* export const api = createApi({
183
187
* baseQuery: fetchBaseQuery({ baseUrl: '/' }),
184
188
* // highlight-start
185
- * extractRehydrationInfo(action, { reducerPath }) {
189
+ * extractRehydrationInfo(action, { reducerPath }): any {
186
190
* if (isHydrateAction(action)) {
187
191
* return action.payload[reducerPath]
188
192
* }
You can’t perform that action at this time.
0 commit comments