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

“send” parameter type is not narrow inside effects #4

Closed
cassiozen opened this issue May 1, 2021 · 3 comments
Closed

“send” parameter type is not narrow inside effects #4

cassiozen opened this issue May 1, 2021 · 3 comments

Comments

@cassiozen
Copy link
Owner

cassiozen commented May 1, 2021

The "send" function argument type should be an union of transition names. It works properly in the send method returned by useStateMachine - but the send method passed to effect currently broadens to "string".

@cassiozen
Copy link
Owner Author

cassiozen commented May 2, 2021

State might need to be a function to enable inference at individual state level. Maybe the API could look like this:

useStateMachine()({
  initialState: 'inactive',
  debugMode: true,
  inactive: stateNode({
    on: { TOGGLE: 'active' },
  }),
  active: stateNode({
    on: { TOGGLE: 'inactive' },
    effect() {
      console.log('Just entered the Active state');
    },
  }),
}
});

@cassiozen
Copy link
Owner Author

cassiozen commented May 3, 2021

Working TS Sample with type narrowing on both send functions: typescript playground

@cassiozen
Copy link
Owner Author

Solved by #11

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