Skip to content

Commit

Permalink
Improve the type of callback invokes
Browse files Browse the repository at this point in the history
  • Loading branch information
VanTanev committed Apr 21, 2021
1 parent e1ac4e3 commit a61d01c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-windows-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate': patch
---

In callback invokes, the types of `callback` and `onReceive` are properly scoped to the machine TEvent.
10 changes: 5 additions & 5 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ export type Receiver<TEvent extends EventObject> = (
listener: (event: TEvent) => void
) => void;

export type InvokeCallback = (
callback: Sender<any>,
onReceive: Receiver<EventObject>
export type InvokeCallback<TEvent extends EventObject = AnyEventObject> = (
callback: Sender<TEvent>,
onReceive: Receiver<TEvent>
) => any;

export interface InvokeMeta {
Expand All @@ -255,7 +255,7 @@ export interface InvokeMeta {
*/
export type InvokeCreator<
TContext,
TEvent = AnyEventObject,
TEvent extends EventObject = AnyEventObject,
TFinalContext = any
> = (
context: TContext,
Expand All @@ -265,7 +265,7 @@ export type InvokeCreator<
| PromiseLike<TFinalContext>
| StateMachine<TFinalContext, any, any>
| Subscribable<any>
| InvokeCallback;
| InvokeCallback<TEvent>;

export interface InvokeDefinition<TContext, TEvent extends EventObject>
extends ActivityDefinition<TContext, TEvent> {
Expand Down

0 comments on commit a61d01c

Please sign in to comment.