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:
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, andserializefunctions - 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
| Concern | Before | After |
|---|---|---|
| Compilation | tsc or nest build | tsgonest build |
| Watch mode | nest start --watch | tsgonest dev |
| Validation | class-validator + class-transformer | Generated from types |
| Serialization | class-transformer + interceptors | Generated fast JSON serializers |
| OpenAPI docs | @nestjs/swagger + decorators | Static analysis, zero decorators |
| Type safety | Runtime decorators (can diverge) | Types are the source of truth |
Two ways to define constraints
JSDoc tags (zero dependencies)
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)
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:
| Metric | Result |
|---|---|
| Validation vs class-validator | 25-84x faster |
| Serialization vs JSON.stringify | ~1.4x faster (simple DTOs) |
| Compilation vs tsc | ~4x faster (full pipeline including companions + OpenAPI) |
Packages
| Package | Description |
|---|---|
tsgonest | The CLI — installs the correct platform binary automatically |
@tsgonest/runtime | defineConfig helper and TsgonestValidationError |
@tsgonest/types | Zero-runtime branded phantom types for type-safe constraints |