Skip to main content

Functions for Creating Types

A function wrapper allows you to utilize closures when creating custom types, opening up a wide range of possibilities.

Usage Examples

  1. Adding a Tag

Caution

For proper schema comparison in the .equal() method, you must use a unique name for each distinct type. In this example, we append the tag to the type name.

  1. Using type or t.none
import { customType, TConvertValueToType } from "encodexx"
export function orNone<T extends TSchema>(type: T) {
if (TYPE_SYMBOL in type) return t.or(t.none, type);
return t.or(t.none, t.schema(type));
}

What’s Next?

For a more advanced example of using functions to create types, check out the examples.