statelyai / xstate

Actor-based state management & orchestration for complex app logic.
https://stately.ai/docs
MIT License
26.51k stars 1.22k forks source link

Bug: [Typescript] Child actor send method event argument is an intersection of all child actor events #4913

Open MichaelSavoia opened 1 month ago

MichaelSavoia commented 1 month ago

XState version

XState version 5

Description

For a machine that invokes multiple actors, when sending events to child actors via the actor.getSnapshot().children.childActor.send() method, the type for the event argument is an intersection of all invoked actors event types. This prevents the ability to pass events that are unique to the applicable actor.

Screenshot 2024-05-28 at 4 55 25 PM

This only applies to the TS types. The child actor behaves as expected when passed an event that fails the TS type.

Expected result

For a machine invoking multiple child actors, when attempting to send an event to a child actor the event argument should accept any valid event for the applicable child actor.

Actual result

The only allowed events are the events shared across all child actors.

Reproduction

https://stackblitz.com/edit/github-2obepf?file=src%2FfeedbackMachine.ts&view=editor

Additional context

No response