class-transformer

Decorator-based transformation between plain objects and class instances for TypeScript

Library
npm
v0.5.1
7,339 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
49 /100 Fair
Development Activity 12
Maintenance 20
Community 64
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
71 /100 Good
Architecture 75
Code Quality 72
Innovation 65
Learning Curve 70

class-transformer converts plain JavaScript objects (the kind you get back from JSON.parse, an HTTP body, or a database driver) into instances of your TypeScript classes, and back again, using decorators like @Type() and @Expose()/@Exclude() to describe the desired shape. Because the output is a real class instance rather than a plain object, methods, getters, and instanceof checks all work correctly on transformed data — something plain object literals can’t provide.

It’s a core building block of the TypeStack ecosystem, most commonly paired with class-validator and used heavily inside NestJS for request DTO transformation and response serialization, but it works standalone in any TypeScript codebase that needs to move data between wire format and typed class instances.

What You Get

  • plainToInstance() / instanceToPlain() for converting between plain objects and class instances
  • @Type() decorator for declaring nested class types so nested objects/arrays transform correctly
  • @Expose() / @Exclude() decorators for controlling which properties appear in serialized output, including per-group and per-version control
  • @Transform() for fully custom per-property transformation logic
  • Circular-reference handling and depth limits for complex object graphs

Common Use Cases

  • Converting incoming HTTP request bodies into typed DTO class instances in NestJS or Express applications
  • Serializing class instances (e.g. entity models) into plain objects for JSON API responses, excluding internal-only fields
  • Pairing with class-validator so class-validator’s decorators run against transformed class instances rather than plain objects
  • Version- or group-scoped serialization, exposing different property sets to different API consumers

Under The Hood

Architecture - The library centers on MetadataStorage (src/MetadataStorage.ts), a singleton registry populated at decoration time by @Type/@Expose/@Exclude/@Transform, and TransformOperationExecutor (src/TransformOperationExecutor.ts, ~555 lines), which walks a source object recursively, consults the stored metadata for each property to decide whether to recurse into a nested @Type-annotated class, apply an exposure/exclusion rule, or run a custom @Transform function, and assembles the resulting plain object or class instance; ClassTransformer.ts exposes the public plainToInstance/instanceToPlain/instanceToInstance entry points over that executor. Tech Stack - Pure TypeScript with reflect-metadata-based decorator support (a peer dependency, not bundled), built to multiple output targets (CJS, ESM5, ES2015, UMD) via separate tsconfig.prod.*.json configs and a Rollup build for the UMD bundle, with zero runtime dependencies beyond reflect-metadata at the consumer’s discretion. Code Quality - test/functional/ contains an extensive suite of scenario tests (nested types, circular references, groups/versions, custom transformers) run via Jest with coverage reporting (codecov.yml), and the codebase is lint-enforced (eslint --max-warnings 0); however GitHub activity data shows the project in a low-commit-frequency, moderately maintained state relative to its very high download volume. API Design - The API surface is small and declarative — a handful of decorators plus two or three top-level functions — which keeps the learning curve low, though correctly wiring @Type() on every nested class property is a common source of confusing bugs for newcomers since it’s easy to forget on deeply nested structures.

Used by 21 apps in this directory

TypeScript
72%
AGPL 3.0

APITable

Databases · Low Code Platforms

15,623

API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.

View details
71
Repo Health
77
Technical
60
Dependency
Built with
TypeScript 72%
Java 22%
Updated 3 weeks ago
TypeScript
96%
Other

Amplication

AI Code Assistants · Automation · Developer Tools

16,015

Create production-ready backend services with your organization's standards baked in — generating NestJS, Prisma, and GraphQL code that you own and control.

View details
58
Repo Health
84
Technical
60
Dependency
Built with
TypeScript 96%
Updated 3 months ago
TypeScript
97%
AGPL 3.0

Bigcapital

Invoicing Finance

3,916

Self-hostable double-entry accounting platform with invoicing, inventory, multi-currency, and real-time financial reporting for small and medium businesses.

View details
90
Repo Health
77
Technical
61
Dependency
Built with
TypeScript 97%
Updated 6 days ago
TypeScript
96%
Other

Cal.diy

Scheduling

48,697

The 100% MIT-licensed, community-driven scheduling platform — self-host your own booking infrastructure with no enterprise strings attached.

View details
91
Repo Health
86
Technical
65
Dependency
Built with
TypeScript 96%
Updated 6 days ago
TypeScript
95%
AGPL 3.0

Docmost

CMS · Collaboration · Note Taking

21,801

Self-hosted collaborative wiki and knowledge base with real-time editing, diagrams, AI assistance, and enterprise access controls — a modern alternative to Confluence and Notion.

View details
89
Repo Health
70
Technical
69
Dependency
Built with
TypeScript 95%
Updated 5 days ago
TypeScript
76%
AGPL 3.0

Ghostfolio

Invoicing Finance

9,367

Track your stocks, ETFs, and crypto with a privacy-first, self-hostable wealth management platform built for data-driven investors.

View details
93
Repo Health
79
Technical
67
Dependency
Built with
TypeScript 76%
HTML 21%
Updated 5 days ago
TypeScript
98%
Other

Hexabot

AI Development · Automation

1,260

Build and run agentic workflows across channels with YAML, tools, and RAG

View details
78
Repo Health
76
Technical
65
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
TypeScript
95%
AGPL 3.0

HeyForm

Forms Surveys · No Code Platforms

8,984

Open-source conversational form builder with AI generation, conditional logic, and 30+ integrations — self-host with full data ownership.

View details
83
Repo Health
67
Technical
67
Dependency
Built with
TypeScript 95%
Updated 3 weeks ago
TypeScript
71%
Other

highlight.io

Analytics · Developer Tools · Monitoring

9,378

Open-source full-stack monitoring that unifies session replay, error tracking, logging, and distributed tracing so you can stop context-switching between tools.

View details
67
Repo Health
78
Technical
65
Dependency
Built with
TypeScript 71%
Go 16%
Updated 1 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers