Skip to content

Commit

Permalink
Fixed an issue with raise return type
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Jul 18, 2020
1 parent 8662e54 commit c1f3d26
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-vans-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate': patch
---

Fixed a type returned by a `raise` action - it's now `RaiseAction<TEvent> | SendAction<TContext, AnyEventObject, TEvent>` instead of `RaiseAction<TEvent> | SendAction<TContext, TEvent, TEvent>`. This makes it comaptible in a broader range of scenarios.
2 changes: 1 addition & 1 deletion packages/core/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export function toActivityDefinition<TContext, TEvent extends EventObject>(
*/
export function raise<TContext, TEvent extends EventObject>(
event: Event<TEvent>
): RaiseAction<TEvent> | SendAction<TContext, TEvent, TEvent> {
): RaiseAction<TEvent> | SendAction<TContext, AnyEventObject, TEvent> {
if (!isString(event)) {
return send(event, { to: SpecialTargets.Internal });
}
Expand Down
17 changes: 15 additions & 2 deletions packages/core/test/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -238,12 +239,24 @@ describe('Raise events', () => {
pending: {
on: {
DECIDE: [
{
actions: raise<GreetingContext, { type: 'ALOHA' }>({
type: 'ALOHA'
}),
cond: (_ctx, ev) => !!ev.aloha
},
{
actions: raise<GreetingContext, { type: 'MORNING' }>({
type: 'MORNING'
}),
cond: (ctx) => ctx.hour < 12
},
{
actions: raise<GreetingContext, GreetingEvent>({
type: 'AFTERNOON'
}),
cond: (ctx) => ctx.hour < 18
},
{
actions: raise({ type: 'EVENING' }),
cond: (ctx) => ctx.hour < 22
Expand Down

0 comments on commit c1f3d26

Please sign in to comment.