Problem Statement
Action type for reducers should be…
Explanation
Use a union with a shared type field, like { type: 'add'; payload: number }. It enables safe, exhaustive switch statements.
Code Solution
SolutionRead Only
type Action =
| { type: 'inc' }
| { type: 'add'; payload: number };
function reducer(state: number, action: Action){
switch(action.type){
case 'inc': return state + 1;
case 'add': return state + action.payload;
}
}