Type Alias DecoderObjectStrict<T>

DecoderObjectStrict: {
    [P in keyof Required<T>]:
        | Decoder<T[P]>
        | { decoder: Decoder<T[P]>; fromKey: string }
}

Represents an object that maps properties of a TypeScript type T to decoders used to validate raw JSON values. Each property may either be a Decoder<T[P]> (decoding a field from the same key in the input JSON) or an object with fromKey and decoder to decode from a different input key.

For the strict variant, the decoder will fail if any keys in the incoming JSON are not present among the resulting set of JSON keys derived from the provided decoders. When a decoder uses fromKey, the allowed JSON key is fromKey rather than the TypeScript property name.

Type Parameters

  • T
interface User { firstName: string; lastName: string; age: number }

const decoders: DecoderObjectStrict<User> = {
firstName: { fromKey: 'first_name', decoder: JsonDecoder.string() },
lastName: { fromKey: 'last_name', decoder: JsonDecoder.string() },
age: JsonDecoder.number()
};