Skip to main content

The optional() Function

Info

You can pass arbitrary arrays and objects to t.optional().

Information

t.optional(schema): TCustomType
  • t.optional() marks a field as not required.
  • You can pass an array, an object, or a type to t.optional.

Example Usage

index.ts
import { Serializer, t } from "encodexx"
const serializer = new Serializer({
age: t.optional(t.uint8),
status: t.optional({
code: t.int16,
msg: t.enumerate("CREATE", "READ", "UPDATE", "DELETE")
}),
logs: t.optional([t.str])
})
serializer.encode({
age: 12,
logs: ["Log_A", "Log_B"]
});