Xstate: Assign in typescript

Created on 26 Sep 2019  路  2Comments  路  Source: davidkpiano/xstate

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]

bug

Most helpful comment

it works as expected with [email protected]

All 2 comments

What happens if you try this with xstate@next?

it works as expected with [email protected]

Was this page helpful?
0 / 5 - 0 ratings