Summary
typia@next uses the ttsc toolchain.
This setup targets TypeScript-Go, the Go migration of the TypeScript compiler. ttsc provides the Go-based plugin toolchain, and typia@next uses the Go-rewritten typia transform.
ttsc: build, check, and watch TypeScript projectsttsx: execute TypeScript directly with type checking@ttsc/unplugin: runttscplugins from bundlers
@typescript/native-preview is not a stable TypeScript release yet, and typia@next is also an experimental release of typia.
Also, you must use ttsc and ttsx. The stock tsc, ts-node, and tsx cannot apply the typia transform, so they will not work.
Setup
Install
npm
npm i typia@next
npm i -D ttsc @typescript/native-previewKeep your TypeScript project strict.
{
"compilerOptions": {
"strict": true
}
}Compile
Use ttsc to build your TypeScript project. It compiles your sources and applies the typia transform in one step.
npm
npx ttsc
npx ttsc --noEmit
npx ttsc --watchExecute
Use ttsx to run a TypeScript file directly, without a build step.
npm
npx ttsx src/index.tsBundlers
Install
Use @ttsc/unplugin
when your project is built by a bundler.
ttsc is enough for a normal TypeScript build, but bundlers run their own
build pipeline. @ttsc/unplugin connects the ttsc transform to that pipeline.
npm
npm i -D @ttsc/unpluginConfiguration
Currently, @ttsc/unplugin supports the following bundlers:
- Vite
- Next.js
- Rollup
- Rolldown
- esbuild
- Webpack
- Rspack
- Farm
- Bun
Then add the matching plugin to your bundler config. Import path must match the bundler you are using.
Vite
import ttsc from "@ttsc/unplugin/vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [ttsc()],
});Put the plugin in the same config file that already builds your application.
For example, a Vite app uses vite.config.ts, a Next.js app uses
next.config.mjs, and a Webpack app uses webpack.config.mjs.
After that, run the normal build command of your framework or bundler.
Project
If your bundler should read another TypeScript config file, pass project.
Vite
import ttsc from "@ttsc/unplugin/vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
ttsc({
project: "tsconfig.bundle.json",
}),
],
});The project path is resolved from the current working directory.
Transform Options
Add compilerOptions.plugins only when you want to change transform options.
{
"compilerOptions": {
"strict": true,
"strictNullChecks": true,
"plugins": [
{
"transform": "typia/lib/transform",
"functional": true, // default: false
"numeric": true, // default: false
"finite": true, // default: false
"undefined": false // default: true
}
]
}
}functional: validate function typesnumeric: rejectNaNfromnumberfinite: reject bothNaNandInfinityfromnumberundefined: setfalseto skip explicitundefinedchecks
If you use the default transform options, do not add
compilerOptions.plugins to tsconfig.json.
ttsc automatically applies the typia transform. This is the difference
from the legacy setup.