-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
sendParent has to returns an event of child type #711
Comments
As a workaround, I just put Have a look at line 75 / notifyClientV4 in machines.ts (only version without an error). So in the example above, you could do this: start: {
onEntry: [sendParent<ChildContext, any>({ type: "PARENT" })]
// ^ Shouldn't be a problem anymore
} EDIT: sidenote, this is how I normally "fix" your second issue import { Interpreter } from 'xstate';
Interface ChildStateSchema {...}
// ...
type ChildActor = Interpreter<ChildContext, ChildStateSchema, ChildEvent>;
// ...
actions: [
() => console.log("hi"),
assign<MachineContext>({
childRef: spawn(child) as ChildActor
// ^ some other problem should be ok now
}) |
Is someone working on this? Or may I help with that? |
Thank you 💛 |
This is great! I'm declaring a wrapper for the child machine so I only have to type the generics once: import { sendParent as sendParentX } from 'xstate'
// ... other imports and declarations for parent/child types
const sendParent = (e: ParentEvent | ParentEvent["type"]): ReturnType<typeof sendParentX> =>
sendParentX<ChildContext, ChildEvent, ParentEvent>(e) |
Description
Using
sendParent
with types (TEvent
) constraintstype
to the events of the child.TodosMachineEvent
!=TodoMachineEvent
Expected Result
sendParent
should be constraint to send parent events, event though theExprWithMeta
event
should be of type of the childActual Result
This is not assignable to
todoMachine
inTodoMVC
example,sendParent
expects theTEvent
to be the type of the child machine eventReproduction
This is a simplified version with the templates
https://codesandbox.io/s/xstate-typescript-error-send-parent-jpzvn
(1) the error is:
(2) Also, In this example I get this warning in the console
Not sure what is that, I understand that
service.start();
should be done, and it is, so i'm not sure of the problem hereAdditional context
xstate@^4.7.0-rc3
The text was updated successfully, but these errors were encountered: