From 5f790ba5478cb733a59e3b0603e8976c11bcdd04 Mon Sep 17 00:00:00 2001 From: David Khourshid Date: Wed, 23 Jun 2021 15:30:00 -0400 Subject: [PATCH] Add changeset --- .changeset/itchy-cameras-hear.md | 12 ++++++++++++ packages/core/src/types.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/itchy-cameras-hear.md diff --git a/.changeset/itchy-cameras-hear.md b/.changeset/itchy-cameras-hear.md new file mode 100644 index 0000000000..82304fa5f8 --- /dev/null +++ b/.changeset/itchy-cameras-hear.md @@ -0,0 +1,12 @@ +--- +'xstate': patch +--- + +The typing for `InvokeCallback` have been improved for better event constraints when using the `sendBack` parameter of invoked callbacks: + +```ts +invoke: () => (sendBack, receive) => { + // Will now be constrained to events that the parent machine can receive + sendBack({ type: 'SOME_EVENT' }); +}; +``` diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index a77d59bd7e..8b2d93912e 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -258,7 +258,7 @@ export interface InvokeMeta { */ export type InvokeCreator< TContext, - TEvent extends EventObject = AnyEventObject, + TEvent extends EventObject, TFinalContext = any > = ( context: TContext,