UNPKG

xstate

Version:

Finite State Machines and Statecharts for the Modern Web.

26 lines (25 loc) 933 B
import { EventDescriptor, EventObject, ExtractEvent } from "./types.js"; /** * Asserts that the given event object is of the specified type or types. Throws * an error if the event object is not of the specified types. * * @example * * ```ts * // ... * entry: ({ event }) => { * assertEvent(event, 'doNothing'); * // event is { type: 'doNothing' } * }, * // ... * exit: ({ event }) => { * assertEvent(event, 'greet'); * // event is { type: 'greet'; message: string } * * assertEvent(event, ['greet', 'notify']); * // event is { type: 'greet'; message: string } * // or { type: 'notify'; message: string; level: 'info' | 'error' } * }, * ``` */ export declare function assertEvent<TEvent extends EventObject, TAssertedDescriptor extends EventDescriptor<TEvent>>(event: TEvent, type: TAssertedDescriptor | readonly TAssertedDescriptor[]): asserts event is ExtractEvent<TEvent, TAssertedDescriptor>;