struct.object
Struct that parses a plain object with a fixed set of fields.
@defjs/core · Function
Signature
function object<T extends ObjectShape>( shape: T, ): ObjectStruct<T>;
shape maps field names to structs.
-
Every field is required by default. A missing key fails with
missing_key. -
.optional()and.nullish()allow a missing key. An absent optional field stays absent in the output. -
.null()/.nullable()allownull. -
.alias(name)sets the field's wire key.struct.parsereads logical keys by default;{ aliases: true }and HTTP JSON decoding read wire keys, and HTTP JSON encoding writes them. Parsed output uses logical keys. -
Keys that are not in
shapeare removed from the output. The output is a new object with anullprototype. -
The input must be a plain object. Arrays,
Map, and class instances fail withinvalid_type(expectedobject). -
Parsing stops at the first failing field, and
issue.pathholds its key. -
Throws
TypeErrorwhenshapeis not a plain object.
ObjectShape is { [key: string]: any }; each value must be a struct.
Parameters
Prop
Type
shape T