Reference core
runtime
# EventLike
A union-typed event. Always carries a string type discriminator.
Members
typereadonly type: string
# Machine
The running machine.
Type Parameters
CES
Members
contextreadonly context: CCurrent context.
statereadonly state: SCurrent state name.
send()send(event): voidSend an event. Synchronous: actions run, listeners fire before return.
###### Parameters
###### event
E###### Returns
voidsubscribe()subscribe(listener): () => voidSubscribe to snapshots. Returns an unsubscribe function.
###### Parameters
###### listener
Listener<C,S>###### Returns
() =>
voidtoJSON()toJSON(): XStateConfig
# MachineConfig
Top-level machine config.
Type Parameters
CES
Members
contextreadonly context: Cidreadonly id: stringinitialreadonly initial: Sstatesreadonly states: { readonly [K in string]: StateNode<C, E, S> }
# Snapshot
A snapshot of the machine.
Type Parameters
CS
Members
contextreadonly context: Cstatereadonly state: S
# StateNode
A state node — entry/exit actions plus an event handler map.
Type Parameters
CES
Members
# Transition
A transition from one state to another, optionally guarded and with actions.
Type Parameters
CES
Members
actions?readonly optional actions?: readonly Action<C, E>[]cond?readonly optional cond?: Guard<C, E>internal?readonly optional internal?: booleanIf true and
targetis omitted, the transition is internal: it executesactionswithout changing state. If false / unset, omittingtargetis the same as targeting the current state (no exit/entry actions fire).target?readonly optional target?: S
# XStateConfig
XState v5–compatible JSON config produced by Machine.toJSON().
Members
contextreadonly context: unknownidreadonly id: stringinitialreadonly initial: stringstatesreadonly states: Record<string, { entry?: ReadonlyArray<string>; exit?: ReadonlyArray<string>; on?: Record<string, { actions?: ReadonlyArray<string>; target?: string; }>; }>
# Action
Action<C, E> = { exec: (context, event) => Partial<C> | void; type: string; } | ((context, event) => Partial<C> | void)An action descriptor.
- Object form ({ type, exec }) — preferred for serialization. Only the string type is exported to JSON, so the visualizer can render the action by name even though exec is a closure. - Function form — convenient for one-off internal actions. Exported to JSON as the literal string "<inline>".
Actions return a partial context patch (or void) — the runtime merges patches into the next context.
Type Parameters
CE
# Guard
Guard<C, E> = (context, event) => booleanA guard predicate evaluated against (context, event).
Type Parameters
CE
Parameters
contextCeventE
Returns
boolean# Listener
Listener<C, S> = (snapshot) => voidListener invoked on every transition (including no-ops).
Type Parameters
CS
Parameters
snapshotSnapshot<C, S>
Returns
void# TransitionLike
TransitionLike<C, E, S> = S | Transition<C, E, S> | ReadonlyArray<S | Transition<C, E, S>>Shorthand: a bare target string is equivalent to { target }. An array means "first guard that passes wins" (XState convention) — useful when one event dispatches to different targets based on payload.
Type Parameters
CES
# defineMachine ( )
defineMachine<C, E, S>(config): (initial?) => Machine<C, E, S>Define a machine factory. The returned function constructs a fresh Machine instance — useful for per-component instances that share a definition.
Type Parameters
CES
Parameters
configMachineConfig<C, E, S>
Returns
(initial?) => Machine<C, E, S>