The name of this decoder (useful for error reporting).
Protected
constructDecodes a value and either succeeds with the decoded value 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
Generated using TypeDoc
Decoder for booelan