xstate
xstate copied to clipboard
Add `assertEventType` helper
Adds a helper function that can be used as an invariant to narrow the type of events that are passed to actions, services, guards, etc.
⚠️ No Changeset found
Latest commit: 2bc82375fd161622bed5e476c81f8f9242342aae
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
I don't mind introducing such a helper but I'm worried that it will give users a false sense of safety. After all - this can throw, how do you respond to the thrown error?
Good point, I wonder if that can be communicated (or is already communicated) in the name and API. I only see this useful when using typescript and in Dev mode.
Maybe an alternative could be a type predicate function, not as ergonomic though IMO - not much benefit over doing the conditional yourself.
Superseded by assertEvent(...) https://stately.ai/docs/typescript#asserting-events
