Replies: 2 comments
-
I'm not sure if this is currently possible (cc. @Andarist) |
Beta Was this translation helpful? Give feedback.
0 replies
-
import { setup, createActor, Snapshot, ActorRef } from "xstate"; // types: 5.9.1
type MyEvent = { type: "myEvent" };
type MyActor = ActorRef<Snapshot<unknown>, MyEvent, any>;
function sendMyEvent(myEventRecevingActor: MyActor) {
myEventRecevingActor.send({ type: "myEvent" });
// @ts-expect-error
myEventRecevingActor.send({ type: "otherEvent" });
}
const machineTakingMyEventAndOtherEvent = setup({
types: {} as {
events:
| {
type: "myEvent";
}
| {
type: "yetAnotherEvent";
};
},
}).createMachine({});
const actorThatAlsoTakesOtherEvent = createActor(
machineTakingMyEventAndOtherEvent,
).start();
// ok
sendMyEvent(actorThatAlsoTakesOtherEvent); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm wondering how to type an ActorLogic that takes a specific event? The ActorLogic should also be able to take other unknown events.
Ideally, a
MyActor
typed variable could be assigned an actor that takes events other thanMyEvent
, but would error withmyActor.send({ type: 'otherEvent' })
Beta Was this translation helpful? Give feedback.
All reactions