微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在Typescripted Redux中,如何找到根减速器的类型?

如何解决在Typescripted Redux中,如何找到根减速器的类型?

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个减速器。如何获得正确的输入?

解决方法

您快到了,只需要组合减速器即可。

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

type RootState = ReturnType<typeof rootReducer>

...
const store = configureStore({
    reducer: rootReducer,...

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。