Legacy (TypeScript v6)
This is the production-stable path. It uses ts-patch on top of the JavaScript TypeScript compiler and is what current published typia releases (v6 line) plug into.
The fastest way to install: run the wizard.
npm
npm install typia
npx typia setupnpx typia setup installs typescript and ts-patch, adds the typia/lib/transform plugin entry to your tsconfig.json, and wires up a prepare script so ts-patch install runs after every npm install. After it finishes, plain tsc builds your project with the typia transform applied.
CI tip. The prepare script runs ts-patch install after every install โ but npm ci --ignore-scripts (which most production / Docker multi-stage installs use) silently skips it. Your production build then compiles without the typia transform, and validators that worked locally throw "no transform has been configured" at runtime. Run npx ts-patch install explicitly right after the npm ci --ignore-scripts step in your pipeline.
If your build pipeline uses a bundler (Vite, Next.js, Webpack, esbuild, โฆ), youโll also want @typia/unplugin.
If your build pipeline uses Babel, SWC, or another tool that doesnโt run TypeScript-compatible transformers, you have to fall back to the generation mode โ typia writes the transformed *.ts files for you ahead of time.
How the transformer works
This is Ahead-of-Time (AOT) compilation.
When you write typia.createIs<IMember>() and compile with tsc, the ts-patch-patched compiler replaces that call site with a hand-written checker specialized to IMember. There is no runtime schema โ only the JavaScript that does exactly the comparisons your IMember type implies.
TypeScript Source
import typia, { tags } from "typia";
import { v4 } from "uuid";
const matched: boolean = typia.is<IMember>({
id: v4(),
email: "samchon.github@gmai19l.com",
age: 30,
});
console.log(matched); // true
interface IMember {
id: string & tags.Format<"uuid">;
email: string & tags.Format<"email">;
age: number &
tags.Type<"uint32"> &
tags.ExclusiveMinimum<19> &
tags.Maximum<100>;
}Two requirements follow from this:
- The build has to run TypeScript-with-transformers. That means stock
tscpatched byts-patch, or a bundler plugin that wraps the same machinery. Babel and SWC strip types before any transformer can see them, so theyโre not supported in this mode โ use generation mode instead. strict(or at leaststrictNullChecks) has to be on. Without strict null checking, your types lie about which fields can benull/undefined, and the emitted validator will lie with them.
Wizard setup
The recommended way.
npm
npm install typia
npx typia setupThe wizard does three things:
- Installs
typescriptandts-patchif they arenโt already devDependencies. - Adds
{ "transform": "typia/lib/transform" }tocompilerOptions.pluginsintsconfig.json. - Adds
"prepare": "ts-patch install"topackage.jsonโsscripts.
Thatโs everything. Run npm run prepare once (or let it run automatically on the next npm install) and tsc will apply the typia transform from then on.
Manual setup
If youโd rather configure it by hand, hereโs what the wizard does:
npm
npm install typia
npm install -D typescript ts-patchAdd the transform plugin to tsconfig.json:
{
"compilerOptions": {
"strict": true,
"strictNullChecks": true,
"skipLibCheck": true,
"plugins": [
{ "transform": "typia/lib/transform" }
]
}
}Add the prepare script to package.json:
{
"scripts": {
"prepare": "ts-patch install"
},
"dependencies": {
"typia": "^6.0.6"
},
"devDependencies": {
"ts-patch": "^3.2.0",
"typescript": "^5.4.5"
}
}Run prepare once so ts-patch patches your local typescript:
npm
npm run prepareAfter that, plain tsc applies the transform.
Bundlers
@typia/unplugin
@typia/unplugin integrates the typia transform into bundlers. It supports:
Install it alongside typia:
npm
npm install typia
npx typia setup
npm install -D @typia/unpluginThen add the matching plugin import to your bundler config:
Vite
You can run any other plugin alongside @typia/unplugin in Vite โ including @vitejs/plugin-react-swc. @typia/unplugin rewrites the TypeScript source before the next plugin sees it, so they donโt conflict.
import UnpluginTypia from '@typia/unplugin/vite'
export default defineConfig({
plugins: [
UnpluginTypia({ /* options */ })
],
})Full options reference lives in the @typia/unplugin README.
Webpack
@typia/unplugin supports Webpack out of the box. The instructions below are the manual ts-loader route for projects that prefer to wire it themselves.
npm
# typia
npm install typia
npx typia setup
# webpack + ts-loader
npm install -D ts-loader webpack webpack-clits-loader runs the patched tsc, so the typia transform applies automatically. Configure as usual:
const path = require("path");
module.exports = {
entry: ["./src/index.tsx"],
output: {
path: path.join(__dirname, "dist"),
filename: "index.js",
},
optimization: { minimize: false },
mode: "development",
target: "node",
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
loader: "ts-loader",
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
};Build with npx webpack. When you strip dev dependencies for production, also pass --ignore-scripts to skip ts-patch install (which would fail because typescript is no longer present):
npm
npx webpack
npm ci --omit=dev --ignore-scriptsFor Node.js backend bundling โ including the popular โsingle bundled JS file with no node_modulesโ pattern โ see the Nestia setup guideย .
NX
npm
npm install typia
npx typia setupAfter installation, make sure the prepare script runs ts-patch install, then add the typia plugin to each @nx/js packageโs tsconfig.lib.json:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": [],
"plugins": [{ "transform": "typia/lib/transform" }]
},
"include": ["**/*.ts"],
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"]
}Nx swallows transformer errors. If typia detects an unsupported type (or anything else), nx <package>:build will succeed but emit JavaScript without the typia transform applied. At runtime youโll see:
Error on typia.createAssert(): no transform has been configured.To get the actual error, run tsc directly:
"targets": {
"build:validate:typia": {
"executor": "nx:run-commands",
"options": {
"commands": [
"tsc --project packages/<package-name>/tsconfig.lib.json --outDir dist/packages/typiaTest"
]
}
}
}Nxโs own transformers option on @nx/js does not work with typia โ it expects a before hook that typia doesnโt expose, because typia operates through ts-patch instead.
Generation
npx typia generate is the fallback for build pipelines where a TypeScript transformer canโt run โ Babel in Create-React-App, raw SWC, and so on. typia reads the input directory or the positional TypeScript source files you pass, expands every typia.*<T>() call site, and writes the transformed source files to the output directory. Your bundler then compiles those transformed files normally.
npm
npm install typia
npm install -D typescript ttsc @typescript/native-preview
npx typia generate \
--input src/templates \
--output src/generated \
--project tsconfig.jsonWhen to use it:
| Build tool | Use this instead |
|---|---|
| Create-React-App / Babel | typia generate |
| Vite / esbuild | @typia/unplugin |
| SWC alone | typia generate |
| Bundlers with SWC inside (Next.js, Vite, โฆ) | @typia/unplugin |
Use --input when all templates live under one directory. When templates live beside feature modules, pass file paths or globs instead:
npx typia generate \
--output src/generated \
--project tsconfig.json \
"src/**/*.typia.ts"File/glob mode writes each selected file as --output/<basename>. Duplicate basenames are rejected instead of overwritten.
--project accepts a tsconfig.json or jsconfig.json file, or a directory containing either file.
When you omit --project, typia searches from the current working directory upward for the nearest tsconfig.json or jsconfig.json.
The input directory or file list contains TypeScript source files that import typia and re-export validators. typia reads each file, applies the transform, and writes the result to --output:
TypeScript Input
import typia from "typia";
import { IMember } from "../structures/IMember";
export const check = typia.createIs<IMember>();Why non-standard compilers arenโt supported directly.
Babel and SWC strip type annotations before any transformer runs. typia needs the type information, so it canโt operate inside those toolchains. Generation mode works around the limitation by running typia ahead of time, producing plain .ts files that any tool can then compile.
Where to go next
- Modern TypeScript-Go alternative โ TypeScript-Go setup
- First validator after setup โ
isยทassertยทvalidate - Why typia needs a transform at all โ Pure TypeScript