gitmyhub

typia

TypeScript ★ 5.9k updated 7h ago

Super-fast/easy runtime validators and serializers via transformation

A TypeScript library that automatically generates fast runtime type-checking functions from your existing TypeScript types, so you never have to write validators or schema files by hand.

TypeScriptViteNext.jsWebpackNode.jssetup: moderatecomplexity 3/5

Typia is a TypeScript library that converts your existing type definitions into real, working runtime checks, without requiring any extra schema definitions or configuration files. Standard TypeScript checks types only during development, meaning bad data can slip through when actual values arrive from a network request or file. Typia closes that gap by reading your TypeScript types at compile time and generating the actual checking functions automatically.

The central mechanic is what the project calls transformation. When you call a Typia function like typia.is(), the compiler replaces that call with a generated type-checking function tailored exactly to your type. You write one line. You do not maintain separate schema files, and you do not write validators by hand. The plain TypeScript type is the single source of truth.

Typia covers several areas beyond basic type checks. It provides JSON parsing and serialization functions that validate data as they convert it, so bad input is caught before it reaches the rest of your application. It supports Protocol Buffers, a compact binary format used in performance-sensitive systems for network communication. A random data generator creates values that match your types, which is useful for testing. There is also a module for LLM function-calling setup, where Typia generates the schemas and validators needed for an AI model to call your code functions directly.

The README includes speed comparisons from benchmarks: the runtime validators are described as 20,000 times faster than a library called class-validator, and the JSON serialization is described as 200 times faster than class-transformer.

Typia requires a custom compilation step. You need to use specific toolchain wrappers rather than the standard TypeScript compiler. Bundler integration with Vite, Next.js, Webpack, and others is available through a plugin. The project is MIT licensed. An online playground at typia.io/playground lets you test how the transformation works before you set anything up locally.

Where it fits