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'
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
Original file line number Diff line number Diff line change @@ -175,14 +175,18 @@ export interface CreateApiOptions<
175175 *
176176 * type RootState = any; // normally inferred from state
177177 *
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
180184 * }
181185 *
182186 * export const api = createApi({
183187 * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
184188 * // highlight-start
185- * extractRehydrationInfo(action, { reducerPath }) {
189+ * extractRehydrationInfo(action, { reducerPath }): any {
186190 * if (isHydrateAction(action)) {
187191 * return action.payload[reducerPath]
188192 * }
You can’t perform that action at this time.
0 commit comments