• Make a decoder that never succeeds and fails with the given message. This is mostly useful for building custom decoders with andThen.

    Type Parameters

    • T

    Parameters

    • message: string

      Custom error message

    Returns Decoder<T>

    A decoder that always fails when executed

    Example

    This example uses expected to create the error message.

    const base64_decoder = Decode.andThen(str => {
    try {
    return Decode.succeed(atob(str));
    } catch {
    return Decode.fail(expected('a valid base64 string', str));
    }
    }, Decode.string);

    decode(base64_decoder, 'SGVsbG8sIFdvcmxkIQ==') === 'Hello, World!'
    decode(base64_decoder, 'invalid$') // Throws

Generated using TypeDoc