You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm new to XState and still learning to use it effectively. I'm unsure if I ran into a bug or if I'm using the library unintentionally.
Problem
I've been struggling for countless hours on this issue. Hopefully, someone has a solution.
My goal is to select context values and send events to a child machine actor of a root machine.
The core of my issue - Typescript doesn't narrow to the selected child actor. This happens once multiple actors are set up on the machine. When I console log the selected actor - It does have the correct value I'm looking for. I've included examples below.
The Error
Property 'context' does not exist on type 'PromiseSnapshot<AuthUser, NonReducibleUnknown> | MachineSnapshot<{ count: number; }, { type: "inc"; } | { type: "dec"; }, {}, {}, string, NonReducibleUnknown, MetaObject, { ...; }>'.
Property 'context' does not exist on type '{ status: "active"; output: undefined; error: undefined; } & { input: NonReducibleUnknown; }'.ts(2339)
Console logging the values outputs the expected actor
I was able to reproduce the issue on code sandbox.
AllanFerencz-Lee
changed the title
Bug: React Context Typescript not resolving children actors when selected.
Bug: React Context Typescript not resolving children actors when selected
Jan 30, 2025
XState version
XState version 5
Description
I'm new to XState and still learning to use it effectively. I'm unsure if I ran into a bug or if I'm using the library unintentionally.
Problem
I've been struggling for countless hours on this issue. Hopefully, someone has a solution.
My goal is to select context values and send events to a child machine actor of a root machine.
The core of my issue - Typescript doesn't narrow to the selected child actor. This happens once multiple actors are set up on the machine. When I console log the selected actor - It does have the correct value I'm looking for. I've included examples below.
The Error
Console logging the values outputs the expected actor
I was able to reproduce the issue on code sandbox.
Navigate to
App.tsx
to see the comments.https://codesandbox.io/p/devbox/busy-mopsa-n2crkj?workspaceId=ws_NiJ4KeBNbFceadwTQwz1Xf
The child machine is invoked in the initial state of the machine.
Is this a bug with XState or am I doing something wrong?
Expected result
Typescript narrowing should find the targeted actor.
Actual result
Typescript fails to narrow to the selected child actor.
Reproduction
https://codesandbox.io/p/devbox/busy-mopsa-n2crkj?workspaceId=ws_NiJ4KeBNbFceadwTQwz1Xf
Additional context
No response
The text was updated successfully, but these errors were encountered: