-
First a quote from @davidkpiano.
Alright, let's get it straight here. First of all the https://codesandbox.io/s/wizardly-wilbur-b19nj?file=/src/index.js Furthermore, you can notice that despite sending The case where I would make a typo in the machine itself and have But TypeScript has weak points too when trying to send events across machines. Even with an explicit generic type, it won't catch a problem. It's probably a bug, but currently, it makes strict mode super helpful. (seen on the last line of the example) Quoting @Andarist again
I would definitely vote for that approach. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 13 replies
-
Could you give an example of that? I feel that I know what you are talking about, but would be great to have this backed up with an example code. |
Beta Was this translation helpful? Give feedback.
-
And about that, the problem is the same when I would want to send an event from within that machine, check line 12 in the linked sandbox. You can't really say that this isn't associated with the machine, right? entry: actions.send('RELRY') Once again, I would love to be proved wrong here and have a solid TS type check on all those cases, but that's not happening right now, and as such the "strict" mode is a necessary evil. |
Beta Was this translation helpful? Give feedback.
-
Right, this should type check OK. This might be a regression from #1178 . I think we might need to introduce overloads for |
Beta Was this translation helpful? Give feedback.
-
I still don't follow, type check is perfectly fine there - it warns about typoed event name. |
Beta Was this translation helpful? Give feedback.
-
I can agree with that. Given that statecharts are a lot about "magic strings", the validation is important to avoid problems that are harder to spot. One might argue that writing tests is important and do I agree with that too, but in case of a typo, it's even harder to find why the code is not working when a machine is just silently ignoring sent events. |
Beta Was this translation helpful? Give feedback.
-
I think that strict mode is not that important anymore when utilizing https://github.com/mattpocock/xstate-codegen. It's not a perfect solution yet, but I think it's the correct path instead of relying on runtime errors. |
Beta Was this translation helpful? Give feedback.
I think that strict mode is not that important anymore when utilizing https://github.com/mattpocock/xstate-codegen. It's not a perfect solution yet, but I think it's the correct path instead of relying on runtime errors.