• This is the same as Decode.at, but implemented in terms of Decode.optionalField instead of Decode.field. This means that the provided value is returned if any object in the given path is missing the next property.

    Type Parameters

    • T

    Parameters

    • name: string
    • value: T

      The value to use if any field is absent

    • child: Decoder<T>

      The decoder to run on that field

    Returns Decoder<T>

    Example

    const decoder = Decode.optionalAt(['outer', 'inner', 'value'], 100, Decode.integer);

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

Generated using TypeDoc