@ue-too/being / index / createStateMachineSchemaWithInferredStates
関数: createStateMachineSchemaWithInferredStates()
createStateMachineSchemaWithInferredStates<
Context,EventPayloadMapping,States,EventOutputMapping>(schema):StateMachineSchema<Context,EventPayloadMapping,ExtractStateNames<States>,EventOutputMapping>
Helper function to create a typed state machine schema with inferred state names. Use this when you have a const states array and want TypeScript to infer the state names.
型パラメーター
Context
Context extends BaseContext
EventPayloadMapping
EventPayloadMapping
States
States extends readonly string[]
EventOutputMapping
EventOutputMapping extends Partial<Record<keyof EventPayloadMapping, unknown>> = DefaultOutputMapping<EventPayloadMapping>
パラメータ
schema
Omit<StateMachineSchema<Context, EventPayloadMapping, ExtractStateNames<States>, EventOutputMapping>, "states"> & object
戻り値
StateMachineSchema<Context, EventPayloadMapping, ExtractStateNames<States>, EventOutputMapping>
例
const states = ["IDLE", "RUNNING", "PAUSED"] as const;
const schema = createStateMachineSchemaWithInferredStates<TimerContext, TimerEvents>({
states,
events: { start: {}, stop: {} },
initialState: "IDLE",
stateDefinitions: [
{
name: "IDLE", // TypeScript knows this must be one of the states
transitions: [
{
event: "start",
targetState: "RUNNING", // TypeScript knows this must be one of the states
}
]
}
]
});