little-state-machine icon indicating copy to clipboard operation
little-state-machine copied to clipboard

Type Error for actions without a payload.

Open numeroflip opened this issue 1 year ago • 0 comments

I have issues with actions which have no payloads (eg. init or reset functions)

import { useStateMachine } from "little-state-machine";

export type GlobalState = {
  stateValue: string;
};

const defaultState: GlobalState = {
  stateValue: "value"
};

export default function Example() {
  const { actions } = useStateMachine({
    reset: () => {...defaultState} // <--- Action without payload
  });

  actions.reset()  // <--- Type Error: expects a payload argument 

  return null
}

image

Reason:

export declare type ActionsOutput<TCallback extends AnyCallback, TActions extends AnyActions<TCallback>> = {
    [K in keyof TActions]: (payload: Parameters<TActions[K]>[1]) => void;
};

numeroflip avatar Jun 14 '23 06:06 numeroflip