0
export const makeStore = () => {
  const store = configureStore({
    reducer: {
      reducer,
      growthReportSlice,
      selectBarSlice,
    },
    ....
  return store;
};
const dummy = makeStore();

export const wrapper = createWrapper(makeStore, { debug: true });
export type AppDispatch = typeof dummy.dispatch;
// export type RootReducer = ReturnType<typeof reducer> &
//   ReturnType<typeof growthReportSlice> &
//   ReturnType<typeof selectBarSlice>;
export const useAppDispatch = () => useDispatch<AppDispatch>();

我只需要根减速器的 ReturnType,但我组合了 3 个减速器。我怎样才能得到正确的打字?

4

1 回答 1

2

你快到了,你只需要组合你的减速器。

import {combineReducers} from 'redux'
const rootReducer = combineReducers({
  reducer,
  growthReportsSlice,
  selectBarSlice
})

type RootState = ReturnType<typeof rootReducer>

...
const store = configureStore({
    reducer: rootReducer,
...
于 2020-10-29T00:06:59.060 回答