UNPKG

862 BTypeScriptView Raw
1import { EventObject } from "./types.js";
2/**
3 * Asserts that the given event object is of the specified type or types. Throws
4 * an error if the event object is not of the specified types.
5 *
6 * @example
7 *
8 * ```ts
9 * // ...
10 * entry: ({ event }) => {
11 * assertEvent(event, 'doNothing');
12 * // event is { type: 'doNothing' }
13 * },
14 * // ...
15 * exit: ({ event }) => {
16 * assertEvent(event, 'greet');
17 * // event is { type: 'greet'; message: string }
18 *
19 * assertEvent(event, ['greet', 'notify']);
20 * // event is { type: 'greet'; message: string }
21 * // or { type: 'notify'; message: string; level: 'info' | 'error' }
22 * },
23 * ```
24 */
25export declare function assertEvent<TEvent extends EventObject, TAssertedType extends TEvent['type']>(event: TEvent, type: TAssertedType | TAssertedType[]): asserts event is TEvent & {
26 type: TAssertedType;
27};