Abstract
Abstract
nameThe name of this decoder (useful for error reporting).
Protected
constructAbstract
decodeDecodes 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
Abstract
testApplies 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
A decoder for T - that knows how to decode a value into a type T or fails with a reason.