statelyai / xstate

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

Bug: SpawnChild input does not see current event #5024

Open xylophonehero opened 3 months ago

xylophonehero commented 3 months ago

XState version

XState version 5

Description

When calling spawnChild in the actions of an event, the input function does not filter to just the event but rather all events in the schema

Expected result

const myMachine = setup({
  types: {} as {
    context: TranscriptionsMachineContext
    events:{ type: 'foo'; value: string } | { type: 'bar' }
  },
}).createMachine({
  on: {
    foo: {
      actions: spawnChild('myActor', {
        input: ({event}) => event.value // HERE
       })
     }
  }
})

event.value should be fine to access

Actual result

event.value is not accessible as the event could be anything event in the schema, not just foo

Reproduction

https://codesandbox.io/p/devbox/wizardly-solomon-7vskzv?file=%2Fsrc%2FfeedbackMachine.ts%3A46%2C16

Additional context

No response