Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xylophonehero opened this issue Nov 13, 2023 · 0 comments

Comments

@xylophonehero
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant