statelyai / xstate

Actor-based state management & orchestration for complex app logic.
https://stately.ai/docs
MIT License
27.18k stars 1.26k forks source link

Bug: Typegen breaks `send` (from `useMachine`) types #3128

Closed bartenra closed 2 years ago

bartenra commented 2 years ago

Description

When I use typegen, I lose the typing of send from useMachine.

Expected result

I expect send to have a type that allows me to use type completion on event names as well as report incorrect event names.

Actual result

send({type: ''}) is not type incorrect, neither do I get type completion

Reproduction

https://codesandbox.io/s/typescript-playground-export-forked-om0pfw?file=/index.ts

Additional context

No response

Andarist commented 2 years ago

Note that this actually wasn't strictly related to the typegen - it's just that raise is at the moment not working overly well (at the type-level) and its usage "deoptimized" the TS inference algorithm. With my fix this should no longer happen - however, raise still doesn't behave totally OK and we should take a closer look at this in the future.