createFsm
Call Signature
Section titled “Call Signature”createFsm<
TInputs>(): <TCtx,TStates,TStateNames,TBubbles>(config) =>Fsm<TCtx, keyofTStates&string, keyofTInputs&string,TBubbles,TInputs>
Defined in: fsm.ts:292
Create a single-client FSM from a config object.
Generic parameters are inferred automatically:
TCtxcomes fromconfig.context(defaults to{}if omitted).TStatesis captured withconstinference to preserve string literal types, enabling compile-time validation of transition targets andhandle()input names.
State names, input names, and all handler signatures derive from TStates.
To type each input’s payload as well (#195), call the curried form with an
input payload map: createFsm<TInputs>()({...}). The zero-argument call
fixes TInputs; the returned function infers everything else from the
config exactly as the direct form does. The split exists because TypeScript
has no partial type-argument inference — the map can’t ride along with the
inferred parameters. Under a map, handler payload parameters are inferred
from the map’s tuples and handle() enforces them at the call site. The
map is also the complete input vocabulary: handler keys outside it are
compile errors.
Type Parameters
Section titled “Type Parameters”TInputs
Section titled “TInputs”TInputs extends InputMapLike<TInputs>
Returns
Section titled “Returns”<TCtx, TStates, TStateNames, TBubbles>(config) => Fsm<TCtx, keyof TStates & string, keyof TInputs & string, TBubbles, TInputs>
Examples
Section titled “Examples”Typed input payloads via the curried form
Call Signature
Section titled “Call Signature”createFsm<
TCtx,TStates,TStateNames,TBubbles>(config):Fsm<TCtx, keyofTStates&string,TBubbles|Exclude<{ [S in string | number | symbol]: keyof TStates[S] & string }[keyofTStates],SpecialStateKeys> | { [S in string | number | symbol]: TStates[S] extends { _child: C } ? InputNamesOfInstance<C> : never }[keyofTStates],TBubbles>
Defined in: fsm.ts:317
Create a single-client FSM from a config object.
Generic parameters are inferred automatically:
TCtxcomes fromconfig.context(defaults to{}if omitted).TStatesis captured withconstinference to preserve string literal types, enabling compile-time validation of transition targets andhandle()input names.
State names, input names, and all handler signatures derive from TStates.
To type each input’s payload as well (#195), call the curried form with an
input payload map: createFsm<TInputs>()({...}). The zero-argument call
fixes TInputs; the returned function infers everything else from the
config exactly as the direct form does. The split exists because TypeScript
has no partial type-argument inference — the map can’t ride along with the
inferred parameters. Under a map, handler payload parameters are inferred
from the map’s tuples and handle() enforces them at the call site. The
map is also the complete input vocabulary: handler keys outside it are
compile errors.
Type Parameters
Section titled “Type Parameters”TCtx extends object = Record<string, never>
TStates
Section titled “TStates”TStates extends Record<string, Record<string, unknown>> = Record<string, Record<string, unknown>>
TStateNames
Section titled “TStateNames”TStateNames extends string = keyof TStates & string
TBubbles
Section titled “TBubbles”TBubbles extends string = never
Parameters
Section titled “Parameters”config
Section titled “config”FsmConfig<TCtx, TStates, TStateNames, TBubbles>
Returns
Section titled “Returns”Fsm<TCtx, keyof TStates & string, TBubbles | Exclude<{ [S in string | number | symbol]: keyof TStates[S] & string }[keyof TStates], SpecialStateKeys> | { [S in string | number | symbol]: TStates[S] extends { _child: C } ? InputNamesOfInstance<C> : never }[keyof TStates], TBubbles>
Examples
Section titled “Examples”Typed input payloads via the curried form