statelyai / xstate-tools

Public monorepo for XState tooling

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Running typegen command on machine with two invokes with one onDone fails

xylophonehero opened this issue · comments

Running npx xstate typegen ... with a machine that looks like the following breaks the command

const myMachine = createMachine({
  tsTypes: {} as import("./myMachine.typegen").Typegen0,
  invoke: [
    {
      id: "firstRequest",
      src: "firstRequest",
      onDone: {
        actions: "onDone",
      },
    },
    {
      id: "secondInvoke",
      src: "secondInvoke",
    },
  ],
});

Error:

myMachine.ts - error,  TypeError: Cannot read properties of undefined (reading 'onDone')
    at xstate_cli_bug/node_modules/@xstate/cli/bin/bin.js:240094:42
    at Array.forEach (<anonymous>)
    at forEachActionRecur (xstate_cli_bug/node_modules/@xstate/cli/bin/bin.js:240089:35)
    at Object.forEachAction (xstate_cli_bug/node_modules/@xstate/cli/bin/bin.js:240161:14)
    at createIntrospectableMachine (xstate_cli_bug/node_modules/@xstate/cli/bin/bin.js:240210:57)
    at getTypegenData2 (xstate_cli_bug/node_modules/@xstate/cli/bin/bin.js:240741:50)
    at xstate_cli_bug/node_modules/@xstate/cli/bin/bin.js:243910:79
    at Array.map (<anonymous>)
    at xstate_cli_bug/node_modules/@xstate/cli/bin/bin.js:243910:10
    at Generator.next (<anonymous>)

Refactored to make the invokes part of two different states so we can get around this