Currently, I am working with a redux-style reducer in ngrx that returns a specific type. However, I have encountered an issue where the TypeScript linter fails to catch invalid properties when using the spread operator in my return object.
Below is the interface I am working with:
interface MyState {
firstName: string;
lastName: string;
age: number;
}
Here is my reducer. The Action
parameter represents an ngrx action:
function reducer(state = initialState, action: Action): MyState {
switch (action.type) {
case Actions.COOL_ACTION:
return {
...state,
propertyDoesNotExist: action.payload, // <- no error
};
default:
return state;
}
}
Although I would expect propertyDoesNotExist
to be flagged as an error, it is not. I have attempted casting the return object as <CalendarState>
, using ...(<CalendarState>state)
for the state property, and trying the as
alias, but none of these solutions have worked.
It seems like the use of the spread operator might be causing issues with the types.