我正在寫一個reducer,我想RESET做state.count = 0
。但是,這給我一個錯誤,number is not assignable to type CounterState
。TypeScript錯誤號不可分配
這裏是我的代碼:
export interface CounterState {
count: number;
};
const initialState: CounterState = {
count: 0
};
export default function counter(state = initialState, action: Action): CounterState {
switch (action.type) {
case TYPES.INCREMENT:
return assign({}, state, {
count: state.count + 1
});
case TYPES.DECREMENT:
return assign({}, state, {
count : state.count - 1
});
case TYPES.RESET:
//error here
return state.count=0;
default:
return state;
}
}
我使用lodash的分配功能。由於