FsmConfig
Defined in: types.ts:343
Configuration object for creating an FSM.
Example
Section titled “Example”Type Parameters
Section titled “Type Parameters”TCtx
The context type (Fsm) or client type (BehavioralFsm).
For Fsm, this is inferred from the context property. For BehavioralFsm,
it’s the client object type provided explicitly or as a generic parameter.
TStates
Section titled “TStates”TStates extends Record<string, Record<string, unknown>> = Record<string, Record<string, unknown>>
The literal states object type. Captured by the factory
function’s generic parameter (ideally with const to preserve string
literal types). Defaults to a loose record for unconstrained usage.
Properties
Section titled “Properties”context?
Section titled “context?”
optionalcontext:TCtx
Defined in: types.ts:370
Initial context data. The type is inferred from this value and flows
into every handler’s ctx parameter.
For BehavioralFsm, this property is optional and serves only as a type constraint — the client object IS the context.
id:
string
Defined in: types.ts:351
Unique identifier for this FSM
initialState
Section titled “initialState”initialState:
NoInfer<keyofTStates&string>
Defined in: types.ts:361
The state to start in. Must be a key of states.
Wrapped in NoInfer to prevent TypeScript from using this value as an
inference site for TStates. Without it, initialState: "green" could
narrow TStates to only have a “green” key. We want inference to come
exclusively from the states property.
states
Section titled “states”states:
ValidateStates<TCtx,TStates>
Defined in: types.ts:373
State definitions. Keys become the state name union.