Improve store typings

Use proper thunk middleware type
This commit is contained in:
Labhansh Agrawal 2021-03-05 01:03:34 +05:30 committed by Benjamin Staneck
parent e554e1db4f
commit 4083839841
3 changed files with 8 additions and 13 deletions

2
lib/hyper.d.ts vendored
View file

@ -190,9 +190,7 @@ export type HyperActions = (
type immutableRecord<T> = {[k in keyof T]: Immutable<T[k]>}; type immutableRecord<T> = {[k in keyof T]: Immutable<T[k]>};
import {ThunkDispatch} from 'redux-thunk';
import configureStore from './store/configure-store'; import configureStore from './store/configure-store';
export type HyperThunkDispatch = ThunkDispatch<HyperState, undefined, HyperActions>;
export type HyperDispatch = ReturnType<typeof configureStore>['dispatch']; export type HyperDispatch = ReturnType<typeof configureStore>['dispatch'];
import {ReactChild} from 'react'; import {ReactChild} from 'react';

View file

@ -1,16 +1,15 @@
import {createStore, applyMiddleware} from 'redux'; import {createStore, applyMiddleware} from 'redux';
import thunk from 'redux-thunk'; import _thunk, {ThunkMiddleware} from 'redux-thunk';
import rootReducer from '../reducers/index'; import rootReducer from '../reducers/index';
import effects from '../utils/effects'; import effects from '../utils/effects';
import * as plugins from '../utils/plugins'; import * as plugins from '../utils/plugins';
import writeMiddleware from './write-middleware'; import writeMiddleware from './write-middleware';
import {composeWithDevTools} from 'redux-devtools-extension'; import {composeWithDevTools} from 'redux-devtools-extension';
import {HyperState, HyperThunkDispatch} from '../hyper'; import {HyperState, HyperActions} from '../hyper';
const thunk: ThunkMiddleware<HyperState, HyperActions> = _thunk;
export default () => { export default () => {
const enhancer = composeWithDevTools( const enhancer = composeWithDevTools(applyMiddleware(thunk, plugins.middleware, thunk, writeMiddleware, effects));
applyMiddleware<HyperThunkDispatch, HyperState>(thunk, plugins.middleware, thunk, writeMiddleware, effects)
);
return createStore(rootReducer, enhancer); return createStore(rootReducer, enhancer);
}; };

View file

@ -1,13 +1,11 @@
import {createStore, applyMiddleware} from 'redux'; import {createStore, applyMiddleware} from 'redux';
import thunk from 'redux-thunk'; import _thunk, {ThunkMiddleware} from 'redux-thunk';
import rootReducer from '../reducers/index'; import rootReducer from '../reducers/index';
import effects from '../utils/effects'; import effects from '../utils/effects';
import * as plugins from '../utils/plugins'; import * as plugins from '../utils/plugins';
import writeMiddleware from './write-middleware'; import writeMiddleware from './write-middleware';
import {HyperState, HyperThunkDispatch} from '../hyper'; import {HyperState, HyperActions} from '../hyper';
const thunk: ThunkMiddleware<HyperState, HyperActions> = _thunk;
export default () => export default () =>
createStore( createStore(rootReducer, applyMiddleware(thunk, plugins.middleware, thunk, writeMiddleware, effects));
rootReducer,
applyMiddleware<HyperThunkDispatch, HyperState>(thunk, plugins.middleware, thunk, writeMiddleware, effects)
);