-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Typing error when sending to parent #570
Comments
This seems similar to TS having problem inferring the types sometimes for sendParent<DefaultContext, EventObject>(ctx => ({ type: 'parent', ctx })), or sendParent((ctx: DefaultContext, ev: EventObject) => ({ type: 'parent', ctx })), fixes this. Ofc this is not ideal, but not sure how much can be done here right now to fix this with current APIs. What I have learned exploring the problem with |
In 4.7, there |
I can't reproduce this right now (at least not inside XState repository). The context type seems to flow correctly to sendParent. |
It shows on the sample project repository, it really is boiled down to the minimum, xstate and typescript are the only packages and this is the tsconfig: {
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"lib": ["es2015"],
"moduleResolution": "node",
"experimentalDecorators": true,
"strict": true
}
} Maybe the I also tried by cloning xstate and linking locally and the type error still appears. I forgot to say that both of the explicit typings mentioned above do not affect the error and it still appears |
@posva What TS version are you using? On 3.5.3, I don't get any type errors. |
@davidkpiano Yeah, I'm really confused I don't understand how you cannot get the error on the repo I sent you. I'm using the latest node v10, packages are up to date, running It all comes to activating |
Loosen types for SendAction. Fixes #570
Bug
Description:
When using
sendParent
in an actions array with the function version, TypeScirpt complains about thestates
property of the machine not being valid. Setting the types of the parent yield the same result:sendParent<ParentContext, ParentEvent>(...)
(Bug) Expected result:
No TS error
(Bug) Actual result:
(Bug) Potential fix:
I think the type should be a bit looser as using a simple
sendParent('parent')
doesn't yield any errorLink to reproduction or proof-of-concept:
I'm sorry I couldn't reproduce the TS error on a codesandbox but this is a fully boiled down repro with only typescript and xstate as deps
https://github.com/posva/xstate-ts-bug
repro steps:
The text was updated successfully, but these errors were encountered: