-
-
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
[V5] [Bug]: typescript errors when spawning actors during context initialization #4566
Comments
There are some issues with this code. if you That being said - even with that fix it doesn't work with TS 5.0. Our types rely currently on a pattern enabled by TS 5.1 ( microsoft/TypeScript#53098 ). I prepared a fix for this here so soon it should also work with TS 5.0 You can see the working example here: TS playground I also wouldn't recommend doing this: const incBy = assign(({ context }, params: number) => {
return { count: context.count + params };
}) as AssignAction<any, any, any, any, any>; While you declared the To fix this it's best to declare your |
Thanks @Andarist as always for your detailed explanation. In the hindsight it make sense to treat
My reproduction uses TS 5.3. I can see that the error goes away in the TS playground when 5.3 is chosen. Not sure, why it is showing the error in stackblitz in spite of the latest typescript version. I get the same problem in my local setup too.
Got it. I do have few common use cases where I would prefer to use shared actions such as |
My bet is that it doesn't really use the TS version installed by your project there but rather whatever they have bundled with their editor.
Could you try using "Select TypeScript version..." from your command palette (I'm assuming that you are using VS Code) and use the workspace version? |
I guess you are right.
I am using Jetbrains. I found a small typescript issue with my code. On fixing that the error in my local setup is gone. Thanks @Andarist. |
Is there an easy way to do that dynamically? I took a quick stab at it and it didn't immediately accept a
but admittedly I didn't spend a lot of time on it. As a workaround, for anyone who finds this, that constraint seems to disappear if you provider input to the actor being spawned. I don't think this is a huge useability problem, since the actor can still be typed fully, but glad to know what the cause is. |
@karlanke Let's open a separate issue for this, so it doesn't get lost 🙏 |
Bug or feature request?
Bug
Description:
When I am trying to spawn an actor during context initialisation, typescript throws an incorrect error linking one of the invokable actors with spawned actor.
(Bug) Expected result:
It should not throw any typescript error
(Bug) Actual result:
Link to reproduction:
https://stackblitz.com/edit/xstate-v5-bug?file=package.json,src%2Fcounter.ts
Additional context
I could not find any
Bug
template for filing bugs. Hence I have filed this using a blank template.The text was updated successfully, but these errors were encountered: