Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Error for actions without a payload. #148

Open
numeroflip opened this issue Jun 14, 2023 · 0 comments
Open

Type Error for actions without a payload. #148

numeroflip opened this issue Jun 14, 2023 · 0 comments

Comments

@numeroflip
Copy link

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;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant