diff --git a/packages/redux-devtools-instrument/src/instrument.ts b/packages/redux-devtools-instrument/src/instrument.ts index c6df45d0..a23f2c36 100644 --- a/packages/redux-devtools-instrument/src/instrument.ts +++ b/packages/redux-devtools-instrument/src/instrument.ts @@ -4,7 +4,6 @@ import isPlainObject from 'lodash/isPlainObject'; import { Action, Observer, - PreloadedState, Reducer, Store, StoreEnhancer, @@ -271,8 +270,8 @@ export const INIT_ACTION = { type: '@@INIT' }; /** * Computes the next entry with exceptions catching. */ -function computeWithTryCatch>( - reducer: Reducer, +function computeWithTryCatch, PreloadedState>( + reducer: Reducer, action: A, state: S, ) { @@ -301,8 +300,8 @@ function computeWithTryCatch>( /** * Computes the next entry in the log by applying an action. */ -function computeNextEntry>( - reducer: Reducer, +function computeNextEntry, PreloadedState>( + reducer: Reducer, action: A, state: S, shouldCatchErrors: boolean | undefined, @@ -316,10 +315,10 @@ function computeNextEntry>( /** * Runs the reducer on invalidated actions to get a fresh computation log. */ -function recomputeStates>( +function recomputeStates, PreloadedState>( computedStates: { state: S; error?: string }[], minInvalidatedStateIndex: number, - reducer: Reducer, + reducer: Reducer, committedState: S, actionsById: { [actionId: number]: PerformAction }, stagedActionIds: number[], @@ -413,11 +412,12 @@ export interface LiftedState, MonitorState> { function liftReducerWith< S, A extends Action, + PreloadedState, MonitorState, MonitorAction extends Action, >( - reducer: Reducer, - initialCommittedState: PreloadedState | undefined, + reducer: Reducer, + initialCommittedState: S | PreloadedState | undefined, monitorReducer: Reducer, options: Options, ): Reducer, LiftedAction> { @@ -575,7 +575,7 @@ function liftReducerWith< if (maxAge && stagedActionIds.length > maxAge) { // States must be recomputed before committing excess. - computedStates = recomputeStates( + computedStates = recomputeStates( computedStates, minInvalidatedStateIndex, reducer, @@ -872,6 +872,7 @@ export type EnhancedStore, MonitorState> = Store< function unliftStore< S, A extends Action, + PreloadedState, MonitorState, MonitorAction extends Action, NextExt, @@ -882,7 +883,9 @@ function unliftStore< LiftedAction > & NextExt, - liftReducer: (r: Reducer) => LiftedReducer, + liftReducer: ( + r: Reducer, + ) => LiftedReducer, options: Options, ) { let lastDefinedState: S & NextStateExt; @@ -924,7 +927,7 @@ function unliftStore< replaceReducer(nextReducer: Reducer) { liftedStore.replaceReducer( liftReducer( - nextReducer as unknown as Reducer, + nextReducer as unknown as Reducer, ) as unknown as Reducer< LiftedState & NextStateExt, LiftedAction @@ -1006,14 +1009,17 @@ export function instrument< ); } - return ( + return < + NextExt extends NonNullable, + NextStateExt extends NonNullable, + >( createStore: StoreEnhancerStoreCreator, ) => - >( - reducer: Reducer, - initialState?: PreloadedState, + , PreloadedState>( + reducer: Reducer, + initialState?: PreloadedState | undefined, ) => { - function liftReducer(r: Reducer) { + function liftReducer(r: Reducer) { if (typeof r !== 'function') { if (r && typeof (r as { default: unknown }).default === 'function') { throw new Error( @@ -1025,7 +1031,13 @@ export function instrument< } throw new Error('Expected the reducer to be a function.'); } - return liftReducerWith( + return liftReducerWith< + S, + A, + PreloadedState, + MonitorState, + MonitorAction + >( r, initialState, monitorReducer, @@ -1057,12 +1069,17 @@ export function instrument< return unliftStore< S, A, + PreloadedState, MonitorState, MonitorAction, NextExt, NextStateExt >( - liftedStore, + liftedStore as Store< + LiftedState & NextStateExt, + LiftedAction + > & + NextExt, liftReducer, options as unknown as Options, );