• Decoder for objects with specified field decoders that fails if unknown fields are present.

    Type Parameters

    • T

    Parameters

    • decoders: DecoderObject<T>

      Key/value pairs of decoders for each object field.

    • decoderName: string

      How to display the name of the object being decoded in errors.

    Returns Decoder<T>

    A decoder that validates and returns objects matching the specified structure, failing if unknown fields are present

    interface User {
    name: string;
    age: number;
    }

    const userDecoder = JsonDecoder.objectStrict<User>(
    {
    name: JsonDecoder.string,
    age: JsonDecoder.number
    },
    'User'
    );

    userDecoder.decode({name: 'John', age: 30}); // Ok<User>
    userDecoder.decode({name: 'John', age: 30, extra: 'field'}); // Err({error: 'Unknown key "extra" found while processing strict <User> decoder'})