The code use the createMachine function exported by xState and this works just fine.
But if you switch to the syntaxe using the TS infered type for spawn will be bad
setup({/* Your setup code */}).createMachine({
// other props skipped...
on: {
'FRIENDS.ADD': {
// actual spawn code
}
}
})
So it's not a bug but documentation is lacking (or at least not clear)
You need to declare your actors in the setup() method and then use a string to refer to them.
XState version
XState version 5
Description
In the "friends-list-react" example you can find the following action spawning a friendMachine
The code use the createMachine function exported by xState and this works just fine. But if you switch to the syntaxe using the TS infered type for spawn will be bad
Expected result
Actual result
Reproduction
https://stackblitz.com/edit/github-qtmqpx?file=src%2FfriendsMachine.ts
Additional context
I'm using Xstate 5.9.1 and I provided a stackblitz link so you can easily see the issue (inside friendsMachine.ts)