diff --git a/extension/src/background/store/apiMiddleware.ts b/extension/src/background/store/apiMiddleware.ts index 06c098d2..e88c841b 100644 --- a/extension/src/background/store/apiMiddleware.ts +++ b/extension/src/background/store/apiMiddleware.ts @@ -18,7 +18,7 @@ import syncOptions, { } from '../../options/syncOptions'; import openDevToolsWindow, { DevToolsPosition } from '../openWindow'; import { getReport } from '../logging'; -import { Action, Dispatch, MiddlewareAPI } from 'redux'; +import { Action, Dispatch, Middleware } from 'redux'; import type { ContentScriptToBackgroundMessage, SplitMessage, @@ -670,10 +670,10 @@ declare global { window.syncOptions = syncOptions(toAllTabs); // Expose to the options page -export default function api( - store: MiddlewareAPI, BackgroundState>, -) { - return (next: Dispatch) => (action: BackgroundAction) => { +const api: Middleware<{}, BackgroundState, Dispatch> = + (store) => (next) => (untypedAction) => { + const action = untypedAction as BackgroundAction; + if (action.type === LIFTED_ACTION) toContentScript(action); else if (action.type === TOGGLE_PERSIST) { togglePersist(); @@ -684,4 +684,5 @@ export default function api( } return next(action); }; -} + +export default api; diff --git a/extension/src/background/store/backgroundReducer.ts b/extension/src/background/store/backgroundReducer.ts index 01ca5a02..fb0f5a7c 100644 --- a/extension/src/background/store/backgroundReducer.ts +++ b/extension/src/background/store/backgroundReducer.ts @@ -1,14 +1,17 @@ import { combineReducers, Reducer } from 'redux'; import { instances, InstancesState } from '@redux-devtools/app'; -import type { BackgroundAction } from './backgroundStore'; +import { BackgroundAction } from './backgroundStore'; export interface BackgroundState { readonly instances: InstancesState; } -const rootReducer: Reducer = - combineReducers({ - instances, - }); +const rootReducer: Reducer< + BackgroundState, + BackgroundAction, + Partial +> = combineReducers({ + instances, +}) as any; export default rootReducer; diff --git a/extension/src/background/store/backgroundStore.ts b/extension/src/background/store/backgroundStore.ts index 21187ce8..595f9479 100644 --- a/extension/src/background/store/backgroundStore.ts +++ b/extension/src/background/store/backgroundStore.ts @@ -1,4 +1,4 @@ -import { createStore, applyMiddleware, PreloadedState } from 'redux'; +import { createStore, applyMiddleware } from 'redux'; import { CustomAction, DispatchAction, @@ -60,7 +60,7 @@ export type BackgroundAction = | DisconnectedAction; export default function configureStore( - preloadedState?: PreloadedState, + preloadedState?: Partial, ) { return createStore(rootReducer, preloadedState, applyMiddleware(api)); /* diff --git a/extension/src/devpanel/store/panelReducer.ts b/extension/src/devpanel/store/panelReducer.ts index 9dc14c71..a6b75a1a 100644 --- a/extension/src/devpanel/store/panelReducer.ts +++ b/extension/src/devpanel/store/panelReducer.ts @@ -30,16 +30,19 @@ export interface StoreStateWithoutSocket { readonly stateTreeSettings: StateTreeSettings; } -const rootReducer: Reducer = - combineReducers({ - instances, - monitor, - reports, - notification, - section, - theme, - connection, - stateTreeSettings, - }); +const rootReducer: Reducer< + StoreStateWithoutSocket, + StoreAction, + Partial +> = combineReducers({ + instances, + monitor, + reports, + notification, + section, + theme, + connection, + stateTreeSettings, +}) as any; export default rootReducer; diff --git a/extension/src/devpanel/store/panelStore.ts b/extension/src/devpanel/store/panelStore.ts index e8ce7ca5..018b7704 100644 --- a/extension/src/devpanel/store/panelStore.ts +++ b/extension/src/devpanel/store/panelStore.ts @@ -1,4 +1,4 @@ -import { createStore, applyMiddleware, Reducer } from 'redux'; +import { createStore, applyMiddleware, Reducer, Store } from 'redux'; import localForage from 'localforage'; import { persistReducer, persistStore } from 'redux-persist'; import { exportStateMiddleware, StoreAction } from '@redux-devtools/app'; @@ -23,6 +23,6 @@ export default function configureStore( panelDispatcher(bgConnection), ); const store = createStore(persistedReducer, enhancer); - const persistor = persistStore(store); + const persistor = persistStore(store as Store); return { store, persistor }; } diff --git a/extension/src/devpanel/store/panelSyncMiddleware.ts b/extension/src/devpanel/store/panelSyncMiddleware.ts index 7c31fcca..278aef75 100644 --- a/extension/src/devpanel/store/panelSyncMiddleware.ts +++ b/extension/src/devpanel/store/panelSyncMiddleware.ts @@ -7,31 +7,33 @@ import { TOGGLE_PERSIST, UPDATE_STATE, } from '@redux-devtools/app'; -import { Dispatch, MiddlewareAPI } from 'redux'; +import { Dispatch, Middleware } from 'redux'; -function panelDispatcher(bgConnection: chrome.runtime.Port) { +function panelDispatcher( + bgConnection: chrome.runtime.Port, +): Middleware<{}, StoreState, Dispatch> { let autoselected = false; const tabId = chrome.devtools.inspectedWindow.tabId; - return (store: MiddlewareAPI, StoreState>) => - (next: Dispatch) => - (action: StoreAction) => { - const result = next(action); - if (!autoselected && action.type === UPDATE_STATE && tabId) { - autoselected = true; - const connections = store.getState().instances.connections[tabId]; - if (connections && connections.length === 1) { - next({ type: SELECT_INSTANCE, selected: connections[0] }); - } + return (store) => (next) => (untypedAction) => { + const action = untypedAction as StoreAction; + + const result = next(action); + if (!autoselected && action.type === UPDATE_STATE && tabId) { + autoselected = true; + const connections = store.getState().instances.connections[tabId]; + if (connections && connections.length === 1) { + next({ type: SELECT_INSTANCE, selected: connections[0] }); } - if (action.type === LIFTED_ACTION || action.type === TOGGLE_PERSIST) { - const instances = store.getState().instances; - const instanceId = getActiveInstance(instances); - const id = instances.options[instanceId].connectionId; - bgConnection.postMessage({ ...action, instanceId, id }); - } - return result; - }; + } + if (action.type === LIFTED_ACTION || action.type === TOGGLE_PERSIST) { + const instances = store.getState().instances; + const instanceId = getActiveInstance(instances); + const id = instances.options[instanceId].connectionId; + bgConnection.postMessage({ ...action, instanceId, id }); + } + return result; + }; } export default panelDispatcher; diff --git a/extension/src/pageScript/index.ts b/extension/src/pageScript/index.ts index 00a4df49..39b00235 100644 --- a/extension/src/pageScript/index.ts +++ b/extension/src/pageScript/index.ts @@ -9,7 +9,6 @@ import { Action, ActionCreator, Dispatch, - PreloadedState, Reducer, StoreEnhancer, StoreEnhancerStoreCreator, @@ -526,34 +525,28 @@ function __REDUX_DEVTOOLS_EXTENSION__>( relayState(liftedState); } - const enhance = - (): StoreEnhancer => - ( - next: StoreEnhancerStoreCreator, - ): any => { - return ( - reducer_: Reducer, - initialState_?: PreloadedState, - ) => { - if (!isAllowed(window.devToolsOptions)) { - return next(reducer_, initialState_); - } + const enhance = (): StoreEnhancer => (next) => { + return , PreloadedState>( + reducer_: Reducer, + initialState_?: PreloadedState | undefined, + ) => { + if (!isAllowed(window.devToolsOptions)) { + return next(reducer_, initialState_); + } - store = stores[instanceId] = configureStore( - next as StoreEnhancerStoreCreator, - monitor.reducer, - { - ...config, - maxAge: getMaxAge as any, - }, - )(reducer_, initialState_) as any; + store = stores[instanceId] = ( + configureStore(next, monitor.reducer, { + ...config, + maxAge: getMaxAge as any, + }) as any + )(reducer_, initialState_) as any; - if (isInIframe()) setTimeout(init, 3000); - else init(); + if (isInIframe()) setTimeout(init, 3000); + else init(); - return store; - }; + return store as any; }; + }; return enhance(); } @@ -598,11 +591,11 @@ export type InferComposedStoreExt = StoreEnhancers extends [ ? HeadStoreEnhancer extends StoreEnhancer ? StoreExt & InferComposedStoreExt : never - : unknown; + : {}; const extensionCompose = (config: Config) => - []>( + ( ...funcs: StoreEnhancers ): StoreEnhancer> => { // @ts-ignore FIXME @@ -619,10 +612,10 @@ const extensionCompose = interface ReduxDevtoolsExtensionCompose { ( config: Config, - ): []>( + ): ( ...funcs: StoreEnhancers ) => StoreEnhancer>; - []>( + ( ...funcs: StoreEnhancers ): StoreEnhancer>; } @@ -635,24 +628,22 @@ declare global { function reduxDevtoolsExtensionCompose( config: Config, -): []>( +): ( ...funcs: StoreEnhancers ) => StoreEnhancer>; function reduxDevtoolsExtensionCompose< - StoreEnhancers extends readonly StoreEnhancer[], + StoreEnhancers extends readonly StoreEnhancer[], >( ...funcs: StoreEnhancers ): StoreEnhancer>; -function reduxDevtoolsExtensionCompose( - ...funcs: [Config] | StoreEnhancer[] -) { +function reduxDevtoolsExtensionCompose(...funcs: [Config] | StoreEnhancer[]) { if (funcs.length === 0) { return __REDUX_DEVTOOLS_EXTENSION__(); } if (funcs.length === 1 && typeof funcs[0] === 'object') { return extensionCompose(funcs[0]); } - return extensionCompose({})(...(funcs as StoreEnhancer[])); + return extensionCompose({})(...(funcs as StoreEnhancer[])); } window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ = reduxDevtoolsExtensionCompose; diff --git a/extension/src/window/store/instanceSelectorMiddleware.ts b/extension/src/window/store/instanceSelectorMiddleware.ts index e10879bc..7587cb8d 100644 --- a/extension/src/window/store/instanceSelectorMiddleware.ts +++ b/extension/src/window/store/instanceSelectorMiddleware.ts @@ -1,4 +1,4 @@ -import { Dispatch, MiddlewareAPI } from 'redux'; +import { Dispatch, Middleware, MiddlewareAPI } from 'redux'; import { SELECT_INSTANCE, StoreAction, @@ -9,7 +9,7 @@ import { function selectInstance( tabId: number, store: MiddlewareAPI, StoreState>, - next: Dispatch, + next: (action: unknown) => unknown, ) { const instances = store.getState().instances; if (instances.current === 'default') return; @@ -33,10 +33,10 @@ function getCurrentTabId(next: (tabId: number) => void) { ); } -export default function popupSelector( - store: MiddlewareAPI, StoreState>, -) { - return (next: Dispatch) => (action: StoreAction) => { +const popupSelector: Middleware<{}, StoreState, Dispatch> = + (store) => (next) => (untypedAction) => { + const action = untypedAction as StoreAction; + const result = next(action); if (action.type === UPDATE_STATE) { if (chrome.devtools && chrome.devtools.inspectedWindow) { @@ -47,4 +47,5 @@ export default function popupSelector( } return result; }; -} + +export default popupSelector; diff --git a/extension/src/window/store/windowReducer.ts b/extension/src/window/store/windowReducer.ts index 458b2760..dab281c9 100644 --- a/extension/src/window/store/windowReducer.ts +++ b/extension/src/window/store/windowReducer.ts @@ -13,17 +13,20 @@ import { import instances from './instancesReducer'; import type { WindowStoreAction } from './windowStore'; -const rootReducer: Reducer = - combineReducers({ - instances, - monitor, - socket, - reports, - notification, - section, - theme, - connection, - stateTreeSettings, - }); +const rootReducer: Reducer< + StoreState, + WindowStoreAction, + Partial +> = combineReducers({ + instances, + monitor, + socket, + reports, + notification, + section, + theme, + connection, + stateTreeSettings, +}) as any; export default rootReducer; diff --git a/extension/src/window/store/windowStore.ts b/extension/src/window/store/windowStore.ts index 43cea9c5..ce746a92 100644 --- a/extension/src/window/store/windowStore.ts +++ b/extension/src/window/store/windowStore.ts @@ -69,7 +69,7 @@ export default function configureStore( ); } const store = createStore(persistedReducer, enhancer); - const persistor = persistStore(store, null, () => { + const persistor = persistStore(store as Store, null, () => { if (store.getState().connection.type !== 'disabled') { store.dispatch({ type: CONNECT_REQUEST, diff --git a/extension/src/window/store/windowSyncMiddleware.ts b/extension/src/window/store/windowSyncMiddleware.ts index 6f9f9cf7..9cdcdfa8 100644 --- a/extension/src/window/store/windowSyncMiddleware.ts +++ b/extension/src/window/store/windowSyncMiddleware.ts @@ -6,16 +6,19 @@ import { TOGGLE_PERSIST, UPDATE_STATE, } from '@redux-devtools/app'; -import { Dispatch, MiddlewareAPI, Store } from 'redux'; +import { Dispatch, Middleware, Store } from 'redux'; import type { BackgroundState } from '../../background/store/backgroundReducer'; -import type { WindowStoreAction } from './windowStore'; import type { BackgroundAction } from '../../background/store/backgroundStore'; const syncStores = - (baseStore: Store) => - (store: MiddlewareAPI, StoreState>) => - (next: Dispatch) => - (action: StoreAction) => { + ( + baseStore: Store, + ): Middleware<{}, StoreState, Dispatch> => + (store) => + (next) => + (untypedAction) => { + const action = untypedAction as StoreAction; + if (action.type === UPDATE_STATE) { return next({ ...action,