【发布时间】:2021-07-01 02:47:33
【问题描述】:
由于我在项目中使用 Immutable.js,因此我很难将 reducer 重构为 TS 这是我的减速机:
export interface DashboardState {
componentId: number | null;
dashboard: number | null;
}
let defaultState: DashboardState = {
componentId: null,
dashboard: null,
};
export default function (state = Map<string, number>(defaultState), action):
Map<string, number> {
switch (action.type) {
case dashboardsActionsTypes.SET_PROJECT_VIEW:
return state.set('componentId', action.payload);
case dashboardsActionsTypes.SET_DASHBOARD_TYPE:
return state.set('dashboard', action.payload);
default:
return state;
}
}
我在 Map(defaultState) 上收到一条错误消息:
我在这里缺少什么?
谢谢
【问题讨论】:
-
Map是一个带有 getter 和 setter 等的映射,无论您在其中存储什么数据。我猜你的状态必须是defaultState : Immutable.Map<string, any>
标签: typescript immutable.js react-typescript