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.

66 msbuild Nest’s own packages, 971 filestsc --noCheck 1,000 ms · swc 185 ms
108 mssave to restarted appnest start --watch 661 ms
288 msdev mode cold startnest start 1,620 ms
267 msJest transform, Nest repots-jest 2,390 ms

Why 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:

Switch in three steps

1. Install

npm i -D @ternlang/ternts@experimental

The 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

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.