Private
fieldsThe name of this decoder (useful for error reporting).
Takes a decoder of U and produces a decoder of T & U. Returns a decoder that can decode all fields of T and U into a single object.
object decoder
an object decoder of T & U
Protected
constructPrivate
constructDecodes a value and either succeeds with the decoded object or fails with a reason.
value to decode
Protected
decodeTakes a decoder of U and produces a decoder of the union of T | U.
Useful for composing decoders that can decode many types.
Example:
asString.or(asNumber) // produces a decoder for string | number
asString.or(asNumber).or(asBoolean)) // produces a decoder for string | number | boolean
A decoder for decoding T | U
Applies an operation that can also fail to this decoder.
const asInt = asNumber.try(num => {
if (Number.isInteger(number)) return success(num)
else return failure("expected integer but got " + num)
})
asInt.parse(117.565) // throws error - $root: expected integer but got 117.565
operation to apply post decoding
a decoder
Removes a key from the object decoder.
field to remove
object decoder with field removed
Generated using TypeDoc
A specific decoder for objects having the shape of T. Has additional methods for specifying the decoding rules of it's fields.