Skip to content

Type Error for actions without a payload. #148

@numeroflip

Description

@numeroflip

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;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions