v0.4.0
Typecasting via as
Downcast an element of a union to a specific variant:
const { id, text } = Action.as.ADD_TODO(someAction) // throws if someAction is not an ADD_TODOPayload properties are merged by default
By default now, the "payload" of a union variant is not put into a separate field but is merged into the same object that contains the tag. That is, instead of having variants of the form
{ tag: 'foo'; value: { x: number; y: boolean } }we have
{ tag: 'foo'; x: number; y: boolean }by default. This is strictly more general in what it can express. You can still recover the old behavior by specifying a valProp when you call unionize. The reason for this change is that it makes it much nicer to use unionize to define props for React components in which "invalid states are unrepresentable".