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 →
48 /100 Fair
Development Activity 8
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
68%
MIT

Hoppscotch

Developer Tools

80,676

A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.

View details
91
Repo Health
83
Technical
62
Dependency
Built with
TypeScript 68%
Vue 24%
Updated 6 days ago
TypeScript
94%
AGPL 3.0

Laudspeaker

Automation · Marketing

2,629

Open-source customer engagement platform for building visual, event-triggered messaging journeys across email, SMS, push, in-app, and webhooks.

View details
45
Repo Health
66
Technical
62
Dependency
Built with
TypeScript 94%
Updated 3 months ago
TypeScript
92%
Other

n8n

Automation · No Code Platforms

208,437

Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.

View details
95
Repo Health
87
Technical
62
Dependency
Built with
TypeScript 92%
Updated 6 days ago
TypeScript
65%
Other

NocoDB

Databases · Low Code Platforms · No Code Platforms

65,340

Turn any SQL database into a collaborative no-code spreadsheet with automatic REST APIs and real-time views.

View details
91
Repo Health
77
Technical
63
Dependency
Built with
TypeScript 65%
Vue 30%
Updated 5 days ago
TypeScript
98%
Other

Novu

Developer Tools

40,195

Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.

View details
93
Repo Health
80
Technical
64
Dependency
Built with
TypeScript 98%
Updated 5 days ago
Clojure
73%
MPL 2.0

Penpot

Design Tools

61,563

Open-source design platform with GPU-accelerated canvas, native design tokens, and MCP-powered AI workflows for teams that ship fast.

View details
91
Repo Health
83
Technical
72
Dependency
Built with
Clojure 73%
Updated 6 days ago
TypeScript
96%
Apache 2.0

Pezzo

AI Development · Monitoring

3,278

Open-source LLMOps platform for prompt management, AI observability, intelligent caching, and real-time cost tracking across LLM providers.

View details
59
Repo Health
75
Technical
66
Dependency
Built with
TypeScript 96%
Updated 2 months ago
TypeScript
81%
AGPL 3.0

Postiz

Automation · Social Media

37,683

The agentic social media scheduler — AI-powered content creation, 33-platform posting, and team workflows, all self-hosted.

View details
92
Repo Health
70
Technical
63
Dependency
Built with
TypeScript 81%
JavaScript 11%
Updated 6 days ago
TypeScript
97%
AGPL 3.0

Swetrix

Analytics

1,213

Privacy-first, cookieless web analytics with error tracking, session replays, and performance monitoring — self-host or use Cloud.

View details
87
Repo Health
71
Technical
66
Dependency
Built with
TypeScript 97%
Updated 1 weeks 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