GitHub

Reference core

runtime

interface 7 type 4 function 1
interface Interfaces 7
interface src/types.ts · L8

# EventLike

A union-typed event. Always carries a string type discriminator.

Members

type
readonly type: string
interface src/types.ts · L97

# Machine

The running machine.

Type Parameters

C
E
S

Members

context
readonly context: C

Current context.

state
readonly state: S

Current state name.

send()
send(event): void

Send an event. Synchronous: actions run, listeners fire before return.

###### Parameters

###### event

E

###### Returns

void

subscribe()
subscribe(listener): () => void

Subscribe to snapshots. Returns an unsubscribe function.

###### Parameters

###### listener

Listener<C, S>

###### Returns

() => void

toJSON()
toJSON(): XStateConfig

Export an XState v5–compatible JSON config (for stately.ai/viz).

###### Returns

XStateConfig

interface src/types.ts · L62

# MachineConfig

Top-level machine config.

Type Parameters

C
E
S

Members

context
readonly context: C
id
readonly id: string
initial
readonly initial: S
states
readonly states: { readonly [K in string]: StateNode<C, E, S> }
interface src/types.ts · L70

# Snapshot

A snapshot of the machine.

Type Parameters

C
S

Members

context
readonly context: C
state
readonly state: S
interface src/types.ts · L55

# StateNode

A state node — entry/exit actions plus an event handler map.

Type Parameters

C
E
S

Members

entry?
readonly optional entry?: readonly Action<C, E>[]
exit?
readonly optional exit?: readonly Action<C, E>[]
on?
readonly optional on?: { readonly [K in string]?: TransitionLike<C, E, S> }
interface src/types.ts · L32

# Transition

A transition from one state to another, optionally guarded and with actions.

Type Parameters

C
E
S

Members

actions?
readonly optional actions?: readonly Action<C, E>[]
cond?
readonly optional cond?: Guard<C, E>
internal?
readonly optional internal?: boolean

If true and target is omitted, the transition is internal: it executes actions without changing state. If false / unset, omitting target is the same as targeting the current state (no exit/entry actions fire).

target?
readonly optional target?: S
interface src/types.ts · L79

# XStateConfig

XState v5–compatible JSON config produced by Machine.toJSON().

Members

context
readonly context: unknown
id
readonly id: string
initial
readonly initial: string
states
readonly states: Record<string, { entry?: ReadonlyArray<string>; exit?: ReadonlyArray<string>; on?: Record<string, { actions?: ReadonlyArray<string>; target?: string; }>; }>
type Type Aliases 4

# 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

C
E

# Guard

Guard<C, E> = (context, event) => boolean

A guard predicate evaluated against (context, event).

Type Parameters

C
E

Parameters

context
C
event
E

Returns

boolean

# Listener

Listener<C, S> = (snapshot) => void

Listener invoked on every transition (including no-ops).

Type Parameters

C
S

Parameters

snapshot
Snapshot<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

C
E
S
function Functions 1

# 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

C
E
S

Parameters

config
MachineConfig<C, E, S>

Returns

(initial?) => Machine<C, E, S>