Stately
XState v6 alpha

TypeScript

Derive types from an XState Store.

XState v6 is in alpha

APIs and behavior may change before the stable release.

Store context, events, emitted events and triggers are inferred from the configuration.

import type { SnapshotFromStore } from '@xstate/store';

type StoreSnapshot = SnapshotFromStore<typeof store>;

Use EventFromStore<typeof store> when another function needs to accept every store event.

import type { EventFromStore } from '@xstate/store';

function sendFromQueue(event: EventFromStore<typeof store>) {
  store.send(event);
}

Prefer derived types over duplicate interfaces. This keeps consumers aligned with the store.

TypeScript cheatsheet

type Snapshot = SnapshotFromStore<typeof store>;
type Context = Snapshot['context'];
type Event = EventFromStore<typeof store>;

On this page