UNPKG

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