'ADMIN' | 'GUEST'
. You can create string literals using combination of t.union
and t.literal
codecs.Story
type is not as clean as it might be. Jasse Hallett in his article proposed a slightly different approach to defining optional values in validator schemas. Lets define a handy optional
combinator!Technically this implies that we expect the given property to be present in every case, but that the value might beundefined
. In practice, that distinction often does not matter, and io-ts will validate an object that is missing a required property if the type of that property is allowed to beundefined
.
Story
definition can be much more cleaner and readable.