#TS7056 error from a very large State Machine

1 messages · Page 1 of 1 (latest)

untold grail
#

Hi all!

I'm currently working on a very large state machine which invokes other complex state machines.

Now the size of the state machine has grown in such a huge size that the Typescript compiler is now complaining about it with the following error:

The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.ts(7056)

I had the same bug previously as well with the Context Provider for React, but this one I managed to solve using this bit of code:

export const BookingFlowMachineContext: ReturnType<
  typeof createActorContext<typeof bookingFlowMachine>
> = createActorContext(bookingFlowMachine);

However I'm not able to do a solution like it, for my very large state machine, due to it having a cyclical reference.

The state machine in question is the one with the name bookingFlowMachine.

Has anyone else had an issue with this before and found a solution?
Currently if I can't get around the typing issue, I would have to decouple each machine and then send data between them through React instead of directly from machine to machine which just seems cumbersome.

Thanks,
Rob

storm drum
#

Oof, do you have a repo I can take a look at to reproduce this?

untold grail
#

I could make something available later this week – currently I'm trying to see if I can define a full type for the "mother" state machine, since I do have type definitions for the invoked machines, so it should be possible

#

Just to add - a pattern I've noticed is this happens whenever a machine too many is added (invoked), as each child along with all their possible states and actions is then added to the "mother" state machine's inferred type

untold grail
#

I hope it's okay that I keep updating this with my findings, it could be someone else has the same issue in the future..

New addition, the issue seems to stem from an invoked machine, which invokes another machine.

So currently I'm exploring typing the triple-layered machine, or just pulling it out from the big machine

storm drum
#

Yes, it's okay 👍

untold grail
#

I couldn't figure out how to properly type the machine, however I did still end up figuring out a solution for my use case – I added the following to the tsconfig

    "declaration": false,
    "declarationMap": false,
    "emitDeclarationOnly": false

And that made the error disappear, since it's only an issue when you need to declare the type from type-inference.. but tbh, not really so strong with these tsconfig options, all I know is it worked 😄

#

P.S. Not sure how to mark this as solved

storm drum
#

I marked it ✅

halcyon dawn
#

@storm drum

Just a note on this error which we've run into.

In v5.16 and before we never see this error. From v5.17 onwards we do. Our main 'parent' state machine, generating the type defs i.e. tradeMachine.d.ts is 1100 lines in v5.16 and over 30k lines in v5.17.

We're still investigating how to work around it other that the above tsconfig changes (which might not fly for us long term) or pinning ourselves to the last working version presumably forever. Or a possibility, but a LOT of work might have to break our parent/child actor relationships and use a message bus to communicate.