I'm using TypeScript 2.x and Redux. I have a reducer which receives an action, based on which I wish to create a new state without some item like this:
export function reducer(state = {}, action) {
switch (action.type) {
case SOME_ACTION:
let newState : { something: string } = state;
delete newState.something;
return newState;
default:
return state;
}
}
Thanks to @basarat I figured out the basics of deleting things ( see TypeScript 2: Remove item from 2-field object). The code above is based on that advice, but now I instead get
TS2322: Type '{}' is not assignable to type '{ something: string; }'.
Property 'something' is missing in type '{}'.
As far as I understand this means that I need to somehow infer the type of the incoming state to delete this item.
What's the best approach to type the Redux state? Or is there an alternative to my approach?