Skip to main content

Schema Creation

The t Object

All built-in types are stored in a single t object. They can be used to type specific data in schemas.

import { t } from "encodexx";
console.log(t)

Usage

To describe a schema using types, pass them to the Serializer class constructor. You can also use arrays and objects to describe more complex structures.

Info

Functions like t.or(), t.optional(), and others return a regular type and can be used just like the rest.

charts.ts
const serializer = new Serializer({
title: t.str,
info: {
chart: [{
xValue: t.or(t.float64, t.str),
yValue: t.or(t.float64, t.str)
}],
status: t.enumerate("200", "201", "400", "500")
}
})

What’s Next?

Read about the types you are interested in in the following chapters.