All blog posts

Introducing: The XState CLI

By Matt Pocock on March 3, 2022Edit this page on GitHub

  • #cli
  • #xstate
  • #announcement
  • #typescript

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.


npm install @xstate/cli


yarn add @xstate/cli


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.


xstate typegen "src/**/*.tsx?" --watch

Runs 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.

Copyright © Stately, 2023