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

Bug: type disagreement between emitted events and toPromise #4931

Closed
boneskull opened this issue Jun 10, 2024 · 0 comments · Fixed by #4932
Closed

Bug: type disagreement between emitted events and toPromise #4931

boneskull opened this issue Jun 10, 2024 · 0 comments · Fixed by #4932
Assignees

Comments

@boneskull
Copy link
Contributor

boneskull commented Jun 10, 2024

XState version

XState version 5

Description

After #4905, there's some problem using toPromise on an actor created from a machine where types.emitted is specified.

Example machine:

const machine = setup({
  types: {
    emitted: {} as {type: 'FOO'}
  }
}).createMachine({
  initial: 'init',
  states: {
    init: {
      entry: [
        emit({type: 'FOO'})
      ],
      always: 'done'
    },
    done: {type: 'final'}
  }
});

Usage:

const actor = createActor(machine).start();
await toPromise(actor) // <-- TS error

Expected result

Would not expect a TS error here.

Actual result

(See playground

Argument of type 'Actor<StateMachine<MachineContext, AnyEventObject, {}, never, never, never, never, "init" | "done", string, NonReducibleUnknown, NonReducibleUnknown, { ...; }, MetaObject, ResolveTypegenMeta<...>>>' is not assignable to parameter of type 'AnyActorRef'.
  Types of property 'on' are incompatible.
    Type '<TType extends "FOO" | "*">(type: TType, handler: (emitted: { type: "FOO"; } & (TType extends "*" ? {} : { type: TType; })) => void) => Subscription' is not assignable to type '<TType extends string>(type: TType, handler: (emitted: EventObject & (TType extends "*" ? {} : { type: TType; })) => void) => Subscription'.
      Types of parameters 'type' and 'type' are incompatible.
        Type 'TType' is not assignable to type '"FOO" | "*"'.
          Type 'string' is not assignable to type '"FOO" | "*"'.

Reproduction

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgUxMGAaOBnZMCuYWMEAClBGrlgMZTICGMyAgjSVHAL5wBmFIOAHIAHthhNkQgNwAoWTQgA7cXBAMaAC2BLkcALw48hABQJZcODACeYZNgBciC5ZRoYzACZOEPBtkQbOychADEAeXChLhcYrgBKADo6RmYAWQ1tXTMXHXRgBgAbELyYIQwXcUlHZ1c4Up8XOstkJRgoaycAbSbmutR0MyDkEIiohN66gF0KvssigHcGaxqhT2UpXq5Z13XdH2GQ3h0i6NjZBLkFZVUNDgM4FMk2DhN1LR1kJKrYE3j5EjkSjAXAmO7Qf6yIA

Additional context

No response

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

Successfully merging a pull request may close this issue.

2 participants