• Same as Decode.field, but it doesn't fail when the property is not present on the object. In that case, the provided value is returned.

    Type Parameters

    • T

    Parameters

    • name: string

      Name of the property

    • value: T

      The value to use if the field is absent

    • child: Decoder<T>

      The decoder to run on the value of that property

    Returns Decoder<T>

    Example

    const decoder = Decode.optionalField('value', 100, Decode.integer);

    decode(decoder, { value: 42 }) === 42
    decode(decoder, {}) === 100
    decode(decoder, 42) // Fails

Generated using TypeDoc