Static analysis of state machines has enormous potential. In this RFC, I'd like to talk about using a CLI tool to generate perfect Typescript types by analysing XState machines in your code.
Typescript with XState is currently imperfect because of XState's innate complexity. The goal is to:
- Get perfect typing of any
MachineOptions
types passed intoMachine
,interpret
,useMachine
etc. This includes typings of events, services, actions, guards and activities based on their usage in the machine. - Get autocomplete on the
matches
function in interpreted state nodes, to allowstate.matches('even.deep.nested.states')
to be type-checkable.
This CLI could, in the future, be tooled to achieve some other stretch goals: