Overview

Native-speed TypeScript compilation with generated validation, serialization, and OpenAPI for NestJS.

tsgonest is a drop-in replacement for the NestJS build toolchain. It compiles your TypeScript via typescript-go, generates runtime validators and fast JSON serializers from your types, and produces an OpenAPI 3.2 document — all in a single tsgonest build command.

Why tsgonest?

NestJS projects typically rely on a stack of runtime libraries — class-validator, class-transformer, @nestjs/swagger — each with its own decorators and manual synchronization. Types defined once in TypeScript get re-declared across these layers.

tsgonest eliminates that. Write plain TypeScript types and everything else is generated at compile time:

src/user/user.dto.ts
import { Min, Max, Email, Trim } from '@tsgonest/types';

export interface CreateUserDto {
  name: string & Trim & Min<1> & Max<255>;
  email: string & Email;
  age: number & Min<0> & Max<150>;
}

Run tsgonest build and you get:

  • Compiled JavaScript (~10x faster than tsc)
  • Companion files with validate, assert, and serialize functions
  • Controllers with injected validation and serialization (zero runtime setup)
  • A complete OpenAPI 3.2 document

No decorators on every property. No reflect-metadata. No runtime overhead.

What it replaces

ConcernBeforeAfter
Compilationtsc or nest buildtsgonest build
Watch modenest start --watchtsgonest dev
Validationclass-validator + class-transformerGenerated from types
Serializationclass-transformer + interceptorsGenerated fast JSON serializers
OpenAPI docs@nestjs/swagger + decoratorsStatic analysis, zero decorators
Type safetyRuntime decorators (can diverge)Types are the source of truth

Two ways to define constraints

JSDoc tags (zero dependencies)

src/user.dto.ts
export interface CreateUserDto {
  /** @minLength 1 @maxLength 255 */
  name: string;

  /** @format email */
  email: string;

  /** @minimum 0 @maximum 150 */
  age: number;
}

Branded phantom types (type-safe, with autocomplete)

src/user.dto.ts
import { Min, Max, Email, Trim } from '@tsgonest/types';

export interface CreateUserDto {
  name: string & Trim & Min<1> & Max<255>;
  email: string & Email;
  age: number & Min<0> & Max<150>;
}

Both approaches generate identical code. Branded types give you IDE autocomplete and compile-time checking of constraints.

Performance

Measured on Apple Silicon, Node.js 25:

MetricResult
Validation vs class-validator25-84x faster
Serialization vs JSON.stringify~1.4x faster (simple DTOs)
Compilation vs tsc~4x faster (full pipeline including companions + OpenAPI)

Packages

PackageDescription
tsgonestThe CLI — installs the correct platform binary automatically
@tsgonest/runtimedefineConfig helper and TsgonestValidationError
@tsgonest/typesZero-runtime branded phantom types for type-safe constraints

Next steps

On this page