Introducing: The XState CLI
Get ready to run XState’s typegen commands outside of VSCode in our all-new CLI.
Around a month ago, we released TypeScript Typegen - an enormous upgrade to the TypeScript experience for XState.
We’ve had a great response to it so far, but it’s only been available for VSCode users.
Until now. With our new XState CLI, you can get Typegen from the command line.
- Read the full documentation on the
@xstate/clidocs. - Check out our updated TypeScript Typegen guide.
- Find the code on the @xstate/cli GitHub repo.
Installation
npm install @xstate/cliOR
yarn add @xstate/cliCommands
xstate typegen <files>
xstate typegen "src/**/*.tsx?"Run the typegen against a glob of files. This will scan every targeted file and generate a typegen file accompanying it. It will also import the typegen into your file, as described in our typegen documentation.
Ensure you wrap your glob in quotes so that it executes correctly. Otherwise, you’ll get unexpected results.
Options
xstate typegen "src/**/*.tsx?" --watchRuns the task on a watch, monitoring for changed files and running the typegen script against them.
The Future
We’re really excited about the CLI, and all the cool things it’ll enable. The typegen really is just the surface. If you’ve got ideas for what we could do with it, don’t hesitate to add a feature request to the xstate-tools repo.