-
Notifications
You must be signed in to change notification settings - Fork 5
04 Utilities
Christoph Fricke edited this page Oct 19, 2021
·
4 revisions
XSystem exports a few utilities that have proofed themself to be useful while developing the package.
A type predicate that narrows an given event to a specific event based in the
event type. It is most useful when defining a transition function for
Behavior
.
import { is } from "xsystem";
type Increment = { type: "increment"; by: number };
type Decrement = { type: "decrement"; by: number };
const event = {} as Increment | Decrement;
if (is<Increment>("increment", event)) {
// event is narrowed to an `Increment` event.
}
if (is<Decrement>("decrement", event)) {
// event is narrowed to an `Decrement` event.
}