Skip to content
2 minute read

Introducing: The XState CLI

Matt Pocock

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.

Installation

npm install @xstate/cli

OR

yarn add @xstate/cli

Commands

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?" --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.