mattpocock / xstate-codegen

A codegen tool for 100% TS type-safety in XState
MIT License
245 stars 12 forks source link

actions/services/activities etc should only be required if there are required entires needed in the config #30

Closed mwarger closed 3 years ago

mwarger commented 4 years ago

The actions object is currently required as part of the options object in the generated useMachine hook, so I have to pass an empty object to quell the type-checking. This should be optional.

rjdestigter commented 4 years ago

I've run into this as well. Including other ones such as services and activities.

mattpocock commented 4 years ago

I think the logic here should be: if any of the actions are required, the 'actions' object should be required. Same for services/activities/guards.

Then, if no activities/actions/guards/services are required, the second parameter of useMachine is not required.

There is also some work here to be done with machine.withConfig - currently withConfig is not typed at all.

mattpocock commented 4 years ago

Broke the second part of my comment off into #32

mwarger commented 3 years ago

I pulled down the project and started looking at this yesterday evening.