The interesting project although it might end up with quite complicated API to cover all cases that XState supports.
As for unions, usually, I do the following when it's hard to have correctly typed one end. It will correctly type-check like that without the need for verbose enum.
export const makeEvent = (name: TLightSwitchEvent) => name
// in the component
send(makeEvent('TOGGLE'))
Not sure why send is not currently typed in this regard. It should ideally be able to infer from the machine itself.
And matches are obvious bigger nut to crack with nesting. I am not sure if TS allows for it dynamically.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The interesting project although it might end up with quite complicated API to cover all cases that XState supports.
As for unions, usually, I do the following when it's hard to have correctly typed one end. It will correctly type-check like that without the need for verbose enum.
Not sure why
send
is not currently typed in this regard. It should ideally be able to infer from the machine itself.And
matches
are obvious bigger nut to crack with nesting. I am not sure if TS allows for it dynamically.