constructor(type: TypeId, optional?: boolean)
View sourceCreates a field descriptor.
Class
Describes one typed field in structured reflection metadata.
A field associates the registered TypeId for a value with whether
the field may be omitted. Its serial form is always an object with type
and optional properties.
const required = new Field('position')
const optional = new Field('velocity', true)
required.serialize() // { type: 'position', optional: false }
optional.serialize() // { type: 'velocity', optional: true }Registered type ID expected for this field’s value.
Whether this field may be omitted. The constructor defaults this to
false, so fields are required unless explicitly marked optional.
serialize(): FieldSerialSerializes this descriptor as its current type and optional values.
No validation or copying of the type ID is performed.
serialize(value: Field): FieldSerialConverts a field descriptor to a plain serial object.
The returned object contains exactly { type: value.type, optional: value.optional }.
deserialize(value: FieldSerial, out?: Field): FieldDeserializes a field serial into a Field instance.
When out is omitted, a new Field is created with the serial’s values.
When out is supplied, its type and optional properties are replaced
in place and the same instance is returned. This method assigns the
supplied properties directly and does not call
Field.validateSerial.
validateSerial(value: unknown): value is FieldSerialChecks whether a value has the serialized field descriptor shape.
Returns true only for a non-null, non-array object with type and
optional properties whose values are a string and boolean respectively.
Extra properties are allowed; this method does not create a Field.