From 408383984125601f15f42ec8a0d797afc58aa3f8 Mon Sep 17 00:00:00 2001 From: Labhansh Agrawal Date: Fri, 5 Mar 2021 01:03:34 +0530 Subject: [PATCH] Improve store typings Use proper thunk middleware type --- lib/hyper.d.ts | 2 -- lib/store/configure-store.dev.ts | 9 ++++----- lib/store/configure-store.prod.ts | 10 ++++------ 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/hyper.d.ts b/lib/hyper.d.ts index ed33bbe5..8914f372 100644 --- a/lib/hyper.d.ts +++ b/lib/hyper.d.ts @@ -190,9 +190,7 @@ export type HyperActions = ( type immutableRecord = {[k in keyof T]: Immutable}; -import {ThunkDispatch} from 'redux-thunk'; import configureStore from './store/configure-store'; -export type HyperThunkDispatch = ThunkDispatch; export type HyperDispatch = ReturnType['dispatch']; import {ReactChild} from 'react'; diff --git a/lib/store/configure-store.dev.ts b/lib/store/configure-store.dev.ts index abc40937..d5b3a430 100644 --- a/lib/store/configure-store.dev.ts +++ b/lib/store/configure-store.dev.ts @@ -1,16 +1,15 @@ import {createStore, applyMiddleware} from 'redux'; -import thunk from 'redux-thunk'; +import _thunk, {ThunkMiddleware} from 'redux-thunk'; import rootReducer from '../reducers/index'; import effects from '../utils/effects'; import * as plugins from '../utils/plugins'; import writeMiddleware from './write-middleware'; import {composeWithDevTools} from 'redux-devtools-extension'; -import {HyperState, HyperThunkDispatch} from '../hyper'; +import {HyperState, HyperActions} from '../hyper'; +const thunk: ThunkMiddleware = _thunk; export default () => { - const enhancer = composeWithDevTools( - applyMiddleware(thunk, plugins.middleware, thunk, writeMiddleware, effects) - ); + const enhancer = composeWithDevTools(applyMiddleware(thunk, plugins.middleware, thunk, writeMiddleware, effects)); return createStore(rootReducer, enhancer); }; diff --git a/lib/store/configure-store.prod.ts b/lib/store/configure-store.prod.ts index fbfae9c6..994b90fd 100644 --- a/lib/store/configure-store.prod.ts +++ b/lib/store/configure-store.prod.ts @@ -1,13 +1,11 @@ import {createStore, applyMiddleware} from 'redux'; -import thunk from 'redux-thunk'; +import _thunk, {ThunkMiddleware} from 'redux-thunk'; import rootReducer from '../reducers/index'; import effects from '../utils/effects'; import * as plugins from '../utils/plugins'; import writeMiddleware from './write-middleware'; -import {HyperState, HyperThunkDispatch} from '../hyper'; +import {HyperState, HyperActions} from '../hyper'; +const thunk: ThunkMiddleware = _thunk; export default () => - createStore( - rootReducer, - applyMiddleware(thunk, plugins.middleware, thunk, writeMiddleware, effects) - ); + createStore(rootReducer, applyMiddleware(thunk, plugins.middleware, thunk, writeMiddleware, effects));