【发布时间】:2018-03-09 02:32:44
【问题描述】:
我正在尝试使用 Typescript 在 Redux 中的状态数组中执行 .map 函数,问题是它抛出错误
[ts] 类型“never”上不存在属性“id”
在landing.id if 语句中,因为它是一个对象数组,所以代码对我来说很有意义,但似乎我在那里遗漏了一些东西
export default function landingReducer (state = [], action) {
switch(action.type) {
case ActionTypes.ADD_LANDING:
return [...state, action.landing]
case ActionTypes.EDIT_LANDING:
return state.map(landing => {
if (action.landing.id == landing.id) {
return landing;
}
})
提前致谢!
【问题讨论】:
标签: typescript redux reducers