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: Not possible to use TS with events #5126

Closed through-space closed 15 hours ago

through-space commented 16 hours ago

XState version

XState version 5

Description

Creating a simple Metronome state machine with knob and one state. The knob changes tempo.

Expected result

'tempo' exists in IMetronomeContext

Actual result

Getting error TS2339: Property tempo does not exist on type AssignArgs<IMetronomeContext, IKnobTurnEvent, IKnobTurnEvent, ProvidedActor>

Reproduction

https://stackblitz.com/edit/github-eucvud?file=src%2FMetronomeStateMachine.ts

Additional context

No response

davidkpiano commented 15 hours ago

See here: https://stackblitz.com/~/edit/github-eucvud-2ekpch?file=src/MetronomeStateMachine.ts:L52

In v5, you must destructure context and event:

-assign((context, event) => { ... })
+assign(({ context, event }) => { ... })
through-space commented 14 hours ago

@davidkpiano You are a wizard. Thank you!