Skip to content

Bug: Can't generate declaration for machine setup #5462

@nagytom

Description

@nagytom

XState version

XState version 5

Description

TypesScript fails to emit declarations for the return type of setup().

Expected result

No TS error and successfully emitted declaration.

Actual result

Two kinds of errors are thrown:

The inferred type of 'machineSetup' cannot be named without a reference to '../node_modules/xstate/dist/declarations/src/guards'. This is likely not portable. A type annotation is necessary.(2742)
Exported variable 'machineSetup' has or is using name 'SpawnActionOptions' from external module "node_modules/xstate/dist/declarations/src/actions/spawnChild" but cannot be named.(4023)
The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.(7056)

Reproduction

https://stackblitz.com/edit/typescript-node-njljw24f

Additional context

This is somehow related to module and moduleResolution tsconfig settings.
Explicitly typing the value could be a challenge due to the complexity of the type relying on inference and self referencing in some cases, e.g. self in the action params.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions