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: UnifiedArg drops the type of emitter from its "self" property #4836

Open
boneskull opened this issue Apr 9, 2024 · 1 comment
Open
Labels

Comments

@boneskull
Copy link

XState version

XState version 5

Description

The self prop of UnifiedArg https://github.com/statelyai/xstate/blob/main/packages/core/src/types.ts#L114 is an ActorRef, but only provides the first two type arguments (snapshot and EventObject for events). The third type arg, which is the "emitter", is left to the default value (EventObject).

Expected result

Given the example in this gist, I'd expect that the self value would be assignable to type ActorRef<any, any, EmittedEvents>.

Actual result

index.ts:24:58 - error TS2322: Type 'ActorRef<MachineSnapshot<{ b?: ActorRef<MachineSnapshot<MachineContext, AnyEventObject, {}, {}, string, NonReducibleUnknown>, AnyEventObject, EventObject> | undefined; }, ... 4 more ..., unknown>, AnyEventObject, EventObject>' is not assignable to type 'ActorRef<any, any, EmittedEvents>'.
  Type 'EventObject' is not assignable to type 'EmittedEvents'.
    Types of property 'type' are incompatible.
      Type 'string' is not assignable to type '"BAR"'.

24       b: ({spawn, self}) => spawn('machineB', { input: { a: self } })
                                                            ~


Found 1 error in index.ts:24

Reproduction

https://gist.github.com/boneskull/a4e139896f661dd0a8288b2af2f0f43d

Additional context

This may be an indication of a larger issue. self doesn't seem all that typesafe. For example, this does not fail compilation:

const machineC = setup({
  types: {
    events: {} as {type: 'FOO'},
    emitted: {} as {type: 'BAR'}
  }
}).createMachine({
  entry: ({self}) => {
    self.on('lkjdshfakdjsfh', () => {});
  }
})
@boneskull boneskull added the bug label Apr 9, 2024
@Andarist
Copy link
Member

Andarist commented Apr 9, 2024

In a sense, this is a duplicate of #4485

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

No branches or pull requests

2 participants