StructMethods
Chainable modifiers available on every Struct instance.
@defjs/core · Type
Signature
interface StructMethods<I, O, OO extends boolean> { alias(name: string): this; null(): Struct<I | null, O | null, OO>; nullable(): Struct<I | null, O | null, OO>; nullish(): Struct<I | null | undefined, O | null | undefined, true>; optional(): Struct<I | undefined, O | undefined, true>; }
Each method returns a new struct and leaves the original unchanged.
-
alias(name)sets the wire name of an object field.struct.parsereads logical names unlessaliases: trueis passed; JSON and flat request codecs write the alias. A non-stringnamethrowsTypeError. -
null()andnullable()are the same: they also acceptnull. -
optional()also acceptsundefined. In an object, the key may be missing, and an absent field stays absent in the output. -
nullish()accepts bothnullandundefined.
Members
Prop
Type
alias (name: string) => StructMethods<I, O, OO>Override the external wire name for this field without changing the TypeScript property name.
null () => Struct<I | null, O | null, OO>Allow null in addition to the current input and output types.
nullable () => Struct<I | null, O | null, OO>Alias for StructMethods.null.
nullish () => Struct<I | null | undefined, O | null | undefined, true>Allow null or undefined, marking the field optional in object output.
optional () => Struct<I | undefined, O | undefined, true>Allow undefined, marking the field optional in object shapes.