xstate 5.33.3 → 5.33.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,13 @@
1
- import { EventDescriptor, EventObject, ExtractEvent } from "./types.js";
1
+ import { EventDescriptor, EventObject } from "./types.js";
2
+ type NormalizeAssertedDescriptor<TDescriptor extends string> = TDescriptor extends '*' ? string : TDescriptor extends `${infer TLeading}.*` ? TLeading | `${TLeading}.${string}` : TDescriptor;
3
+ type AssertedEvent<TEvent extends EventObject, TDescriptor extends string> = (TEvent extends {
4
+ type: infer TType extends string;
5
+ } ? true extends (TType extends NormalizeAssertedDescriptor<TDescriptor> ? true : false) ? TEvent : never : never) | (string extends TEvent['type'] ? TEvent : never);
2
6
  /**
3
7
  * Asserts that the given event object is of the specified type or types. Throws
4
8
  * an error if the event object is not of the specified types.
9
+ * Partial wildcard descriptors such as `feedback.*` match both `feedback` and
10
+ * its descendants, such as `feedback.good`.
5
11
  *
6
12
  * @example
7
13
  *
@@ -22,4 +28,5 @@ import { EventDescriptor, EventObject, ExtractEvent } from "./types.js";
22
28
  * },
23
29
  * ```
24
30
  */
25
- export declare function assertEvent<TEvent extends EventObject, TAssertedDescriptor extends EventDescriptor<TEvent>>(event: TEvent, type: TAssertedDescriptor | readonly TAssertedDescriptor[]): asserts event is ExtractEvent<TEvent, TAssertedDescriptor>;
31
+ export declare function assertEvent<TEvent extends EventObject, TAssertedDescriptor extends EventDescriptor<TEvent>>(event: TEvent, type: TAssertedDescriptor | readonly TAssertedDescriptor[]): asserts event is AssertedEvent<TEvent, TAssertedDescriptor>;
32
+ export {};
@@ -193,7 +193,7 @@ export type TransitionsConfig<TContext extends MachineContext, TEvent extends Ev
193
193
  };
194
194
  type PartialEventDescriptor<TEventType extends string> = TEventType extends `${infer TLeading}.${infer TTail}` ? `${TLeading}.*` | `${TLeading}.${PartialEventDescriptor<TTail>}` : never;
195
195
  export type EventDescriptor<TEvent extends EventObject> = TEvent['type'] | PartialEventDescriptor<TEvent['type']> | '*';
196
- type NormalizeDescriptor<TDescriptor extends string> = TDescriptor extends '*' ? string : TDescriptor extends `${infer TLeading}.*` ? `${TLeading}.${string}` : TDescriptor;
196
+ type NormalizeDescriptor<TDescriptor extends string> = TDescriptor extends '*' ? string : TDescriptor extends `${infer TLeading}.*` ? TLeading | `${TLeading}.${string}` : TDescriptor;
197
197
  export type IsLiteralString<T extends string> = string extends T ? false : true;
198
198
  type DistributeActors<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject, TTransitionMeta extends MetaObject, TSpecificActor extends ProvidedActor> = TSpecificActor extends {
199
199
  src: infer TSrc;