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.
@@ -9,9 +9,33 @@ var assign = require('./assign-76f14f49.cjs.js');
9
9
  var log = require('./log-81c55f77.cjs.js');
10
10
  require('./xstate-dev.cjs.js');
11
11
 
12
+ // `AssertedEvent` is kept local to this module rather than reusing
13
+ // `ExtractEvent` (types.ts) so that the narrowing also resolves when `TEvent` is
14
+ // an unresolved generic type parameter, e.g.:
15
+ //
16
+ // function example<T extends SomeEventUnion>(event: T) {
17
+ // assertEvent(event, 'someType');
18
+ // event.someProp; // previously a type error; now narrows correctly
19
+ // }
20
+ //
21
+ // Two details make that work while still matching what `ExtractEvent` does:
22
+ //
23
+ // 1. We match `{ type: infer TType }` and test the fresh `TType` parameter
24
+ // instead of indexing `TEvent['type']` inside the distribution over
25
+ // `TEvent`. Indexing a still-unresolved generic `TEvent` leaves the whole
26
+ // conditional opaque, so every property access on the "narrowed" event then
27
+ // fails.
28
+ // 2. Testing the inferred `TType` also lets the descriptor check distribute
29
+ // over a union-typed `type` field, so an event like `{ type: 'a' | 'b' }` is
30
+ // still matched by the descriptor `'a'` (mirroring `ExtractEvent`'s
31
+ // `EventDescriptorMatches`). Plain assignability
32
+ // (`TEvent extends { type: 'a' }`) would instead throw such an event away.
33
+
12
34
  /**
13
35
  * Asserts that the given event object is of the specified type or types. Throws
14
36
  * an error if the event object is not of the specified types.
37
+ * Partial wildcard descriptors such as `feedback.*` match both `feedback` and
38
+ * its descendants, such as `feedback.good`.
15
39
  *
16
40
  * @example
17
41
  *
@@ -9,9 +9,33 @@ var assign = require('./assign-6e49963c.development.cjs.js');
9
9
  var log = require('./log-ef4ad2a1.development.cjs.js');
10
10
  require('./xstate-dev.development.cjs.js');
11
11
 
12
+ // `AssertedEvent` is kept local to this module rather than reusing
13
+ // `ExtractEvent` (types.ts) so that the narrowing also resolves when `TEvent` is
14
+ // an unresolved generic type parameter, e.g.:
15
+ //
16
+ // function example<T extends SomeEventUnion>(event: T) {
17
+ // assertEvent(event, 'someType');
18
+ // event.someProp; // previously a type error; now narrows correctly
19
+ // }
20
+ //
21
+ // Two details make that work while still matching what `ExtractEvent` does:
22
+ //
23
+ // 1. We match `{ type: infer TType }` and test the fresh `TType` parameter
24
+ // instead of indexing `TEvent['type']` inside the distribution over
25
+ // `TEvent`. Indexing a still-unresolved generic `TEvent` leaves the whole
26
+ // conditional opaque, so every property access on the "narrowed" event then
27
+ // fails.
28
+ // 2. Testing the inferred `TType` also lets the descriptor check distribute
29
+ // over a union-typed `type` field, so an event like `{ type: 'a' | 'b' }` is
30
+ // still matched by the descriptor `'a'` (mirroring `ExtractEvent`'s
31
+ // `EventDescriptorMatches`). Plain assignability
32
+ // (`TEvent extends { type: 'a' }`) would instead throw such an event away.
33
+
12
34
  /**
13
35
  * Asserts that the given event object is of the specified type or types. Throws
14
36
  * an error if the event object is not of the specified types.
37
+ * Partial wildcard descriptors such as `feedback.*` match both `feedback` and
38
+ * its descendants, such as `feedback.good`.
15
39
  *
16
40
  * @example
17
41
  *
@@ -9,9 +9,33 @@ import { s as sendTo, l as log, e as enqueueActions, a as emit } from './log-d16
9
9
  export { S as SpecialTargets, a as emit, e as enqueueActions, f as forwardTo, l as log, b as sendParent, s as sendTo } from './log-d1660d4b.development.esm.js';
10
10
  import './xstate-dev.development.esm.js';
11
11
 
12
+ // `AssertedEvent` is kept local to this module rather than reusing
13
+ // `ExtractEvent` (types.ts) so that the narrowing also resolves when `TEvent` is
14
+ // an unresolved generic type parameter, e.g.:
15
+ //
16
+ // function example<T extends SomeEventUnion>(event: T) {
17
+ // assertEvent(event, 'someType');
18
+ // event.someProp; // previously a type error; now narrows correctly
19
+ // }
20
+ //
21
+ // Two details make that work while still matching what `ExtractEvent` does:
22
+ //
23
+ // 1. We match `{ type: infer TType }` and test the fresh `TType` parameter
24
+ // instead of indexing `TEvent['type']` inside the distribution over
25
+ // `TEvent`. Indexing a still-unresolved generic `TEvent` leaves the whole
26
+ // conditional opaque, so every property access on the "narrowed" event then
27
+ // fails.
28
+ // 2. Testing the inferred `TType` also lets the descriptor check distribute
29
+ // over a union-typed `type` field, so an event like `{ type: 'a' | 'b' }` is
30
+ // still matched by the descriptor `'a'` (mirroring `ExtractEvent`'s
31
+ // `EventDescriptorMatches`). Plain assignability
32
+ // (`TEvent extends { type: 'a' }`) would instead throw such an event away.
33
+
12
34
  /**
13
35
  * Asserts that the given event object is of the specified type or types. Throws
14
36
  * an error if the event object is not of the specified types.
37
+ * Partial wildcard descriptors such as `feedback.*` match both `feedback` and
38
+ * its descendants, such as `feedback.good`.
15
39
  *
16
40
  * @example
17
41
  *
@@ -9,9 +9,33 @@ import { s as sendTo, l as log, e as enqueueActions, a as emit } from './log-6a5
9
9
  export { S as SpecialTargets, a as emit, e as enqueueActions, f as forwardTo, l as log, b as sendParent, s as sendTo } from './log-6a5e50a8.esm.js';
10
10
  import './xstate-dev.esm.js';
11
11
 
12
+ // `AssertedEvent` is kept local to this module rather than reusing
13
+ // `ExtractEvent` (types.ts) so that the narrowing also resolves when `TEvent` is
14
+ // an unresolved generic type parameter, e.g.:
15
+ //
16
+ // function example<T extends SomeEventUnion>(event: T) {
17
+ // assertEvent(event, 'someType');
18
+ // event.someProp; // previously a type error; now narrows correctly
19
+ // }
20
+ //
21
+ // Two details make that work while still matching what `ExtractEvent` does:
22
+ //
23
+ // 1. We match `{ type: infer TType }` and test the fresh `TType` parameter
24
+ // instead of indexing `TEvent['type']` inside the distribution over
25
+ // `TEvent`. Indexing a still-unresolved generic `TEvent` leaves the whole
26
+ // conditional opaque, so every property access on the "narrowed" event then
27
+ // fails.
28
+ // 2. Testing the inferred `TType` also lets the descriptor check distribute
29
+ // over a union-typed `type` field, so an event like `{ type: 'a' | 'b' }` is
30
+ // still matched by the descriptor `'a'` (mirroring `ExtractEvent`'s
31
+ // `EventDescriptorMatches`). Plain assignability
32
+ // (`TEvent extends { type: 'a' }`) would instead throw such an event away.
33
+
12
34
  /**
13
35
  * Asserts that the given event object is of the specified type or types. Throws
14
36
  * an error if the event object is not of the specified types.
37
+ * Partial wildcard descriptors such as `feedback.*` match both `feedback` and
38
+ * its descendants, such as `feedback.good`.
15
39
  *
16
40
  * @example
17
41
  *