-
Notifications
You must be signed in to change notification settings - Fork 42
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: typegen does not like invoke functions returning machines #298
Comments
We plan to rethink how parent-child communication is done in v5 and hopefully, this will get fixed holistically then. The problem here is that we don't have any special generic slot for the "output data" of machines. It seems that we've used the declared I think that both of those places should behave the same. I'm not sure though how this should be adjusted. We have a dilemma here:
- done: { type: "final", data: (c) => c.foo }
+ done: { type: "final", data: (c) => c } However, the |
In a way passing the whole context up from the child gives us type safety, because the invoke property checks it. It forces the parent to conform to the child's type though, which can be problematic if the child starts with some undefined state that becomes defined in the final state 🤷 I would personally go with
Do you have anything to share on this? 😄 |
I ran into this as well. Might be good to add to the Typescript section in the documentation |
Description
We use factories to create machines with parameters that are then invoked from other machines. Typegen is unhappy when the invoke function returns a machine from the factory, but is happy if we pass the machine directly.
We tried passing context from parent to child using
data
, but it doesn't seem to be typesafe — typos indata
are not checked against the actual context of the invoked machine.Expected result
Typegen is happy.
Actual result
It looks like typegen compares the context of the invoked machine against the services schema:
The machine runs fine though (see the sandbox). If you remove the
() =>
then the type errors go away. Alternatively, if we change the services schema todata: any
that also fixes it.Reproduction
https://codesandbox.io/s/thirsty-rosalind-gifq27?file=/src/App.tsx
Additional context
No response
The text was updated successfully, but these errors were encountered: