Skip to content

Using the Schemas

The generated files are plain TypeBox schema objects, so you use them like any other TypeBox schema. Import from the model.ts re-export file and validate data at runtime or derive a static type, from the exact same object.

Runtime validation and static types

ts
import type { Static } from "typebox";
import { Value } from "typebox/value";
import { Post, PostInputCreate } from "./prismatype/model";

// Runtime validation
if (!Value.Check(PostInputCreate, req.body)) {
  throw new Error("Invalid post");
}

// Compile-time type, derived from the same schema
type Post = Static<typeof Post>;

Use with frameworks

Because they are ordinary TypeBox schemas, they drop straight into frameworks built on TypeBox, such as Elysia or Fastify (with the TypeBox type provider):

ts
import { Elysia } from "elysia";
import { PostInputCreate } from "./prismatype/model";

new Elysia().post("/posts", ({ body }) => createPost(body), {
  body: PostInputCreate,
});

Match your import source

If your app imports TypeBox from a re-export (e.g. Elysia), set typeboxImportDependencyName so the generated files import from the same place. Otherwise you may end up with two distinct TypeBox instances.

Released under the MIT License.