Why action type is connected to specific event type? #1649
-
Related to #1387 I use Reproduction and you need to see only My question is that why action needs specific event type? Action shouldn't be connected to only one event. It can be used at several events like 1:N connection. Is this intention? and how can I solve it? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
The However, for your assign call, you're not even using event, so perhaps there are ways to improve this on the XState side, but for now, |
Beta Was this translation helpful? Give feedback.
-
Because, it is just example to show error. I'm using event in my real codebase and it is causing error. But, there is no compilation error, just VSCODE is showing error. Therefore, I think there are two solutions.
What is best choice? |
Beta Was this translation helpful? Give feedback.
-
The best choice depends on what do you feel is right for your use case and how much type-safe you want to get in a particular situation. |
Beta Was this translation helpful? Give feedback.
The
assign<TContext, TEvent>(...)
action creator currently needs the specific event type because you might use theevent
in the assignment itself, and of course, you can't just assume any event when it can only be a specific type of event for the transitionHowever, for your assign call, you're not even using event, so perhaps there are ways to improve this on the XState side, but for now,
assign<SomeContext, any>(...)
suffices.