statelyai / xstate-tools

Public monorepo for XState tooling

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@xstate/cli typegen regression from 0.5.2

laat opened this issue · comments

When generating types with 0.5.4, type checking with typescript gives the error 'actionA' does not exist in type 'MachineOptionsActions...

It worked in 0.5.2

import { createMachine } from 'xstate';

const machine = createMachine(
  {
    schema: {
      services: {} as {
        getData: {
          data: any;
        };
      },
    },
    tsTypes: {} as import('./foo.typegen').Typegen0,
    predictableActionArguments: true,

    initial: 'A',
    context: {
      value: '',
    },
    states: {
      A: {
        invoke: {
          src: 'getData',
          onDone: {
            actions: ['actionA', 'actionB'],
            target: 'DONE',
          },
        },
      },
      B: {
        invoke: {
          src: 'getData',
          onDone: {
            actions: ['actionA', 'actionB'],
            target: 'DONE',
          },
        },
      },
      DONE: {},
    },
  },
  {
    actions: {
      actionA: () => {}, // <-- ts error "'actionA' does not exist in type ..."
      actionB: () => {},
    },
  }
);

The only difference from the typegen.ts file generated in 0.5.2 is this:

   eventsCausingActions: {
-    actionA:
-      | 'done.invoke.(machine).A:invocation[0]'
-      | 'done.invoke.(machine).B:invocation[0]';
     actionB:
       | 'done.invoke.(machine).A:invocation[0]'
       | 'done.invoke.(machine).B:invocation[0]';
   };

Thanks for the report - I'll look into it very soon.

thanks! v0.5.5 solved it 👍