xstate icon indicating copy to clipboard operation
xstate copied to clipboard

Add `assertEventType` helper

Open tom-sherman opened this issue 3 years ago • 5 comments

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.

tom-sherman avatar Dec 23 '21 14:12 tom-sherman

⚠️ 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

changeset-bot[bot] avatar Dec 23 '21 14:12 changeset-bot[bot]

CodeSee Review Map:

Review these changes using an interactive CodeSee Map

Review in an interactive map

View more CodeSee Maps

Legend

CodeSee Map Legend

ghost avatar Dec 23 '21 14:12 ghost

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?

Andarist avatar Dec 23 '21 14:12 Andarist

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.

tom-sherman avatar Dec 23 '21 15:12 tom-sherman

Maybe an alternative could be a type predicate function, not as ergonomic though IMO - not much benefit over doing the conditional yourself.

tom-sherman avatar Dec 23 '21 15:12 tom-sherman

Superseded by assertEvent(...) https://stately.ai/docs/typescript#asserting-events

davidkpiano avatar Jan 02 '24 14:01 davidkpiano