How to implement state pattern in match api?

I would like to pass my StateMachine class as MatchState parameter to make my life easier,
but I’m getting stack overflow.

Here is the code snipped and error log:

Here is my tsconfig.json:

{
  "compilerOptions": {
    /* Visit https://aka.ms/tsconfig to read more about this file */
    "typeRoots": ["./node_modules"],
    "target": "ES5",                                  /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
    "outFile": "./build/index.js",                                  /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
    "esModuleInterop": true,                             /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
    // "preserveSymlinks": true,                         /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
    "forceConsistentCasingInFileNames": true,            /* Ensure that casing is correct in imports. */

    /* Type Checking */
    "strict": true,                                    /* Enable all strict type-checking options. */
    "strictPropertyInitialization": true
  },
  "include": [
    "./src/**/*"
  ],
  "exclude": [
    "node_modules",
    "build"
  ],
}

It looks like you’re creating a self-referential loop as you’re passing machine to itself within the .change() method.
This causes issues because Nakama has to walk the state object to apply some reference changes. You’ll need to change your code to prevent this self-reference.

Storing objects in the state is also not recommended as it’s not fully supported and can cause issues in some cases, it would be best to make it a POJO and have some class or plain functions to manipulate it.

Hope this helps

Thank you for the answer! It make sense.