redux中使用combineReducers严格的typescript类型定义应该怎么写呢?

新手上路,请多包涵
type rootState = {
  count: typeof countInitialValue;
  name: typeof nameInitialValue;
};

type rootAction = CountActionType | NameActionType;

const reducers = combineReducers<rootState, rootAction>({
  count: countReducer,
  name: nameReducer
});

如果rootAction写成上面那样错误信息

TS2322: 
Type 'Reducer<{ count: number; }, CountActionType>' is not assignable to type 'Reducer<{ count: number; }, rootAction>'.   
Types of parameters 'action' and 'action' are incompatible.     
Type 'rootAction' is not assignable to type 'CountActionType'.       
Type '{ type: "SET_NAME"; name: string; }' is not assignable to type 'CountActionType'.         
Type '{ type: "SET_NAME"; name: string; }' is not assignable to type '{ type: "MINUS_NUMBER"; }'.

我看了它的定义,还是没有明白应该怎么写

export type ReducersMapObject<S = any, A extends Action = Action> = {
  [K in keyof S]: Reducer<S[K], A>;
};

求助~

阅读 1.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进