Skip to content

v0.4.0

Choose a tag to compare

@pelotom pelotom released this 30 Aug 07:50
· 95 commits to master since this release

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_TODO

Payload 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".