Skip to content

Commit 6e38609

Browse files
committed
Update Redux store types
1 parent 6ed56f4 commit 6e38609

5 files changed

Lines changed: 15 additions & 13 deletions

File tree

src/ui/actions/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Action, AnyAction, Store, ThunkAction } from "@reduxjs/toolkit";
1+
import { Action, Store, ThunkAction, UnknownAction } from "@reduxjs/toolkit";
22

33
import debuggerActions from "devtools/client/debugger/src/actions";
44
import { QuickOpenActions } from "devtools/client/debugger/src/actions/quick-open";
@@ -21,7 +21,7 @@ export type UIThunkAction<TReturn = void> = ThunkAction<
2121
TReturn,
2222
UIState,
2323
ThunkExtraArgs,
24-
AnyAction
24+
UnknownAction
2525
>;
2626

2727
export type UIStore = AppStore;

src/ui/components/SourcesContextAdapter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default function SourcesContextWrapper({ children }: PropsWithChildren) {
3333
(location: PartialLocation | null) => {
3434
if (location === null) {
3535
if (selectedLocation !== null) {
36-
dispatch(clearSelectedLocation);
36+
dispatch(clearSelectedLocation());
3737
}
3838
} else {
3939
if (

src/ui/setup/hooks.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// We ban use of `useDispatch/useSelector` in the codebase in favor of the typed hooks,
22
// but this is the one file that needs them
33
// eslint-disable-next-line no-restricted-imports
4-
import { TypedUseSelectorHook, useDispatch, useSelector, useStore } from "react-redux";
4+
import { useDispatch, useSelector, useStore } from "react-redux";
55

66
import type { UIState } from "ui/state";
77

88
import type { AppDispatch, AppStore } from "./store";
99

1010
// Use throughout your app instead of plain `useDispatch` and `useSelector`
11-
export const useAppStore = useStore as () => AppStore;
12-
export const useAppDispatch: () => AppDispatch = useDispatch;
13-
export const useAppSelector: TypedUseSelectorHook<UIState> = useSelector;
11+
export const useAppStore = useStore.withTypes<AppStore>();
12+
export const useAppDispatch = useDispatch.withTypes<AppDispatch>();
13+
export const useAppSelector = useSelector.withTypes<UIState>();

src/ui/setup/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ declare global {
3535
}
3636
}
3737

38-
// Just to grab the type of Dispatch
39-
let store: UIStore;
40-
export type AppDispatch = typeof store.dispatch;
38+
export type { AppDispatch } from "./store";
4139

4240
const getDefaultSelectedPrimaryPanel = (
4341
session: ReplaySession | undefined,

src/ui/setup/store.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Reducer,
44
Store,
55
ThunkDispatch,
6+
UnknownAction,
67
combineReducers,
78
configureStore,
89
} from "@reduxjs/toolkit";
@@ -105,9 +106,12 @@ export function bootstrapStore(initialState: Partial<UIState>) {
105106
return store;
106107
}
107108

108-
export type AppStore = ReturnType<typeof bootstrapStore>;
109-
// TODO Actually duplicated this with ./index.ts
110-
export type AppDispatch = AppStore["dispatch"];
109+
type BaseAppStore = ReturnType<typeof bootstrapStore>;
110+
// Explicitly include ThunkDispatch since the @ts-ignore on middleware
111+
// prevents TS from inferring it from the store's dispatch type.
112+
export type AppDispatch = ThunkDispatch<UIState, ThunkExtraArgs, UnknownAction> &
113+
BaseAppStore["dispatch"];
114+
export type AppStore = Omit<BaseAppStore, "dispatch"> & { dispatch: AppDispatch };
111115

112116
export function extendStore(
113117
store: Store,

0 commit comments

Comments
 (0)