• Make decoder that runs the given function and uses its result for decoding. This can be used for nested decoding, where you would otherwise get a Cannot access 'value' before initialization error.

    Type Parameters

    • T

    Parameters

    Returns Decoder<T>

    A decoder that calls the given function when its executed. The returned value is what will then be used for decoding.

    Example

    class Tree {}

    const tree_decoder = Decode.instance(Tree, {
    value: Decode.field('value', Decode.integer),
    children: Decode.field(
    'children',
    Decode.lazy(() => Decode.many(tree_decoder)),
    ),
    });

    const raw = {
    value: 42,
    children: [
    { value: 43, children: [] },
    {
    value: 44,
    children: [
    { value: 45, children: [] },
    ],
    },
    ]
    };

    decode(tree_decoder, raw) // Decodes the nested tree structure

Generated using TypeDoc