import { Action, ActionCreatorsMapObject } from "redux"; export interface ActionWithPayload extends Action { payload: P; } // Overload the createAction function types export function createAction(type: T): Action; export function createAction( type: T, payload?: P ): ActionWithPayload; export function createAction(type: T, payload?: P) { return payload === undefined ? { type } : { type, payload }; } /** * `A` is an object with a bunch of key: createAction() in it. * Type ActionsUnion is all of the return types for each of those createActions (SimpleAction, ActionWithPayload) */ export type ActionsUnion = ReturnType< A[keyof A] >;