Description
Assign does not behaves as expected in typescript, it I assign the Event type to assign it becomes unassignable to the machine
Expected Result
Be able to type
const machine = Machine<Context, Schema, Event>({
id: "machine",
initial: "inactive",
context: {
count: 0
},
states: {
inactive: {
on: {
TOGGLE: [
{
target: "active",
actions: [
assign<Context, Event>({
// ^ this is not possible
count: (ctx, e) =>
e.type === "TOGGLE" ? ctx.count + 1 : ctx.count
})
]
}
]
}
},
active: {
on: {
TOGGLE: [
{
target: "inactive"
}
]
}
}
}
});
Actual Result
Type 'AssignAction<Context, Event>' is not assignable to type 'string'.
Reproduction
https://codesandbox.io/s/xstate-typescript-error-with-assign-v18b4
Additional context
"strict": true
[email protected]
What happens if you try this with xstate@next?
it works as expected with [email protected]
Most helpful comment
it works as expected with
[email protected]