nurbol.dev

nurbol.dev

Typing reducer actions

Separating reducer action into separate type template
provides cleaner readability of reducer action typing

export type ReducerAction<T, P> = {
  type: T;
  payload: P;
};

export type ShoppingListActions =
  | ReducerAction<'ADD_ITEM', ShoppingListItem>
  | ReducerAction<'UPDATE_ITEM', { index: number; item: ShoppingListItem }>
  | ReducerAction<'DELETE_ITEM', { index: number }>
  | ReducerAction<'UPDATE_NEW_SHOPPING_ITEM_NAME', string>;