diff --git a/.changeset/gentle-vans-visit.md b/.changeset/gentle-vans-visit.md new file mode 100644 index 0000000000..27e55516cc --- /dev/null +++ b/.changeset/gentle-vans-visit.md @@ -0,0 +1,5 @@ +--- +'xstate': patch +--- + +Fixed a type returned by a `raise` action - it's now `RaiseAction | SendAction` instead of `RaiseAction | SendAction`. This makes it comaptible in a broader range of scenarios. diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index f44e66e2cd..e9691d0c02 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -159,7 +159,7 @@ export function toActivityDefinition( */ export function raise( event: Event -): RaiseAction | SendAction { +): RaiseAction | SendAction { if (!isString(event)) { return send(event, { to: SpecialTargets.Internal }); } diff --git a/packages/core/test/types.test.ts b/packages/core/test/types.test.ts index 3ec14c3e8c..63bfe51d72 100644 --- a/packages/core/test/types.test.ts +++ b/packages/core/test/types.test.ts @@ -213,12 +213,13 @@ describe('Raise events', () => { } type GreetingEvent = - | { type: 'DECIDE' } + | { type: 'DECIDE'; aloha?: boolean } | { type: 'MORNING' } | { type: 'LUNCH_TIME' } | { type: 'AFTERNOON' } | { type: 'EVENING' } - | { type: 'NIGHT' }; + | { type: 'NIGHT' } + | { type: 'ALOHA' }; interface GreetingContext { hour: number; @@ -238,12 +239,24 @@ describe('Raise events', () => { pending: { on: { DECIDE: [ + { + actions: raise({ + type: 'ALOHA' + }), + cond: (_ctx, ev) => !!ev.aloha + }, { actions: raise({ type: 'MORNING' }), cond: (ctx) => ctx.hour < 12 }, + { + actions: raise({ + type: 'AFTERNOON' + }), + cond: (ctx) => ctx.hour < 18 + }, { actions: raise({ type: 'EVENING' }), cond: (ctx) => ctx.hour < 22