XState: Empty machine template

Languages

typescript5.6.3

Libraries

xstate5.18.2
GithubCode

Template to initialize an empty machine for XState v5. The template contains types, context, actions, actors, and one placeholder Idle state.

import { setup } from "xstate";

export const machine = setup({
  types: {
    context: {} as {},
    events: {} as Readonly<{ type: "event" }>,
    input: {} as {},
    children: {} as {},
  },
  actions: {},
  actors: {},
}).createMachine({
  id: "",
  context: {},
  initial: "Idle",
  states: {
    Idle: {},
  },
});

See the thinking behind the code.

Get one focused idea about type-safe software, AI-assisted development, and the architecture behind maintainable systems.

Join 1,000+ readers. Free, no spam, unsubscribe anytime. See the privacy policy.