Hi guys,
I'm trying to type the response from the promise service using the guide from the docs https://xstate.js.org/docs/guides/typescript.html#typegen but it's not quite working for me.
const machine = createMachine({
id: 'myMachine',
initial: 'decision',
schema: {
services: {} as {
makeDecision: {
data: { id: string }
}
},
},
states: {
decision: {
invoke: {
src: 'makeDecision',
onDone: [
{
target: 'selectAmount',
cond: (context, event) => { // <== event.data has type any
return true
},
},
{
target: 'notEligible',
},
],
onError: {
target: 'error',
},
},
},
selectAmount: {},
notEligible: {},
error: {},
},
})
I have a guard, as you can see above and the event.data has type any no matter what.
The service implementation is in the useMachine
const [state, send] = useMachine(machine, {
services: {
async makeDecision() {
// ...
},
},
})
What do I do wrong?
Documentation for XState: State Machines and Statecharts for the Modern Web