What is the best way to cast the action parameter in a redux reducer with typescript? There will be multiple action interfaces that can occur that all extend a
For a relatively simple reducer you could probably just use type guards:
function isA(action: IAction): action is IActionA {
return action.type === 'a';
}
function isB(action: IAction): action is IActionB {
return action.type === 'b';
}
function reducer(action: IAction) {
if (isA(action)) {
console.info('action a: ', action.a);
} else if (isB(action)) {
console.info('action b: ', action.b);
}
}