Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Callback services not typed correctly #89

Open
@bahalperin

Description

@bahalperin

The definitions for InvokeCallback and InvokeCreator are currently:

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

export type InvokeCreator<
  TContext,
  TEvent extends EventObject,
  TFinalContext = any
> = (
  context: TContext,
  event: TEvent,
  meta: InvokeMeta
) =>
  | PromiseLike<TFinalContext>
  | StateMachine<TFinalContext, any, any>
  | Subscribable<EventObject>
  | InvokeCallback<any, TEvent>;

xstate-codegen narrows the event type down to the event that caused the transition and invoked the service. This makes the event type for the Sender in the InvokeCallback the same. It should be able to send any of the machine's events back to it, regardless of what event caused the service to be invoked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions