ternTS · Guide
Faster NestJS builds and restarts.
A NestJS app runs on the decorator metadata tsc emits. ternTS emits that exact output in a fraction of the time, so you can swap out nest build and nest start --watch without your app noticing.
nest start --watch 661 msnest start 1,620 msWhy NestJS can’t use just any fast compiler
Nest’s dependency injection reads the constructor parameter types that emitDecoratorMetadata writes into your compiled code (design:paramtypes). @nestjs/swagger, @nestjs/graphql and TypeORM read design:type as well. A compiler that skips that metadata, or gets it slightly wrong, gives you an app that builds fine and then fails at startup with “Nest can’t resolve dependencies”, or quietly produces a different API schema.
esbuild doesn’t emit decorator metadata at all. swc does, with its own helpers. ternTS writes the same program tsc does (the outputs are parsed and compared, ignoring only formatting and the numbering of temp names like _a), and that’s checked three ways:
- All 1,959 files in the NestJS repository compile to the same program as TypeScript 5.9’s.
- All 3,631 of Nest’s unit tests pass with ternTS as the transformer.
- Nine Nest sample apps built with tsc and with ternTS answer the same requests byte for byte, including the Swagger document and GraphQL schema Nest builds from metadata.
Switch in three steps
1. Install
npm i -D @ternlang/ternts@experimentalThe package ships a native binary for macOS and Linux (arm64 and x64) and WebAssembly for everything else. There’s no postinstall script and nothing to compile.
2. Point your scripts at ternTS
A project made by nest new builds with tsconfig.build.json, the config that leaves out tests. Give ternTS the same one:
// package.json
"scripts": {
"build": "ternts build -p tsconfig.build.json",
"start:dev": "ternts dev -p tsconfig.build.json --warm",
"start:prod": "node dist/main"
}ternts build reads outDir, module, target, paths and the decorator options from your tsconfig, uses every core, and skips files that haven’t changed. ternts dev builds, runs node dist/main.js, and restarts on every save. --warm keeps a standby Node process with your packages already loaded, so a restart doesn’t pay for loading @nestjs/core again. To run something other than node dist/main.js, put it after --.
3. Keep type checking
ternTS only transpiles, like swc and esbuild. Keep tsc --noEmit (or tsgo) in CI or your editor so type errors still fail the build:
"typecheck": "tsc --noEmit -p tsconfig.build.json"
Tests too
Nest’s default Jest config uses ts-jest. Change one line in the jest section of package.json:
"transform": {
"^.+\\.(t|j)s$": "@ternlang/ternts/jest"
}ternTS hoists jest.mock() calls the way ts-jest and @swc/jest do. On the Nest repository, one worker, source maps on, the transform takes 267 ms against ts-jest’s 2,390 ms. More in the Jest guide.
What isn’t done yet
- ternTS is experimental. If any file comes out differently from
tsc, please open an issue. - It doesn’t report type errors. ternTS turns TypeScript into JavaScript, but like swc and esbuild it never checks that your types are right, so code with type errors still builds. Keep
tsc --noEmitrunning for that, as in step 3 above. - No ES5 output. Every target from ES2015 up is lowered the way tsc lowers it.
- On Windows,
ternts buildruns as WebAssembly.ternts devdoesn’t run there yet.
Numbers are from an Apple M4 Pro with Node 24, swc 1.16.12, TypeScript 5.9.3 and tsgo 7.0.2. Dev-mode times are the median of 20 edits to Nest’s cats sample. node bench/run.mjs in the ternTS repository reproduces them.