Defjs
Core

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.parse reads logical names unless aliases: true is passed; JSON and flat request codecs write the alias. A non-string name throws TypeError.

  • null() and nullable() are the same: they also accept null.

  • optional() also accepts undefined. In an object, the key may be missing, and an absent field stays absent in the output.

  • nullish() accepts both null and undefined.

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.

Edit this page on GitHub
Released under the MIT License. · Copyright © 2026 MunMunMiao