Skip to Content

typia (validators)

typia is the canonical example of a compile-powered plugin. It reads your TypeScript types at build time and generates dedicated JavaScript that validates, serializes, or randomizes data at runtime β€” no reflection, no schema duplication.

ttsc ships typia integration out of the box. Just register the transform.

Install

npm install typia

(Yes, just typia. The transform is included in the package.)

Configure

// tsconfig.json { "compilerOptions": { "plugins": [ { "transform": "typia/lib/transform" } ] } }

Use it

import typia, { tags } from "typia"; interface IMember { id: string & tags.Format<"uuid">; email: string & tags.Format<"email">; age: number & tags.Type<"uint32"> & tags.ExclusiveMinimum<19> & tags.Maximum<100>; } const member: IMember = { id: "8f5d2f3a-3f3b-4a3a-9bba-3a3b4a3a9bba", email: "samchon.github@gmail.com", age: 30, }; const matched: boolean = typia.is<IMember>(member); const random: IMember = typia.random<IMember>(); const json: string = typia.json.stringify<IMember>(member);

Try it before installing

The Playground ships with typia wired in. Edit the source, watch the generated JS.

What you can do with typia

FunctionPurpose
typia.is<T>(x)Type guard β€” returns boolean.
typia.assert<T>(x)Throws on mismatch, returns the validated T.
typia.validate<T>(x)Returns either { success: true, data } or { success: false, errors }.
typia.random<T>()Generate a random instance of T.
typia.json.stringify<T>(x)Faster, schema-aware JSON serialization.
typia.json.assertParse<T>(s)Parse + validate in one call.
typia.protobuf.encode<T>(x)Encode T as protobuf using the type as schema.

Full reference: typia.io/docs .

How it works under ttsc

When ttsc sees a call like typia.is<IMember>(), the typia transform reads IMember from the TypeScript-Go Checker, generates a dedicated validator function for that exact shape, and emits the generated function as the call body.

Output (heavily condensed):

const matched = (() => { const _io0 = (input) => "string" === typeof input.id && /* …uuid regex check… */ "string" === typeof input.email && /* …email regex check… */ "number" === typeof input.age && Number.isInteger(input.age) && 19 < input.age && input.age <= 100; return (input) => "object" === typeof input && null !== input && _io0(input); })()(member);

Zero runtime reflection. No schema separate from the type. The validator only knows about the fields your interface declared.

Frameworks built on typia

  • nestia β€” NestJS controllers + OpenAPI + SDK generation, all driven by typia.assert.
  • @ttsc/lint β€” different problem, same plugin protocol. Lint as compile errors.
Last updated on