typestack/class-transformer: the newest tag is from 2021 and the branch is develop
Decorator-based transformation, serialization, and deserialization between objects and classes.
At a glance
- What is it?
- class-transformer maps plain JavaScript objects onto class instances with decorators, which is the answer to a specific problem: JSON.parse hands you objects that are not instances, so the methods on your class do not exist. Everything else about the project is infrastructure detail worth knowing, including a hard dependency on the reflect-metadata shim, a default build that emits only CommonJS, and a sample folder whose name contains a typo.
- Who is it for?
- The library fits a codebase whose models are real classes with behaviour on them and whose data arrives as parsed JSON, especially an API whose response shape needs explicit control. It does not fit a team that wants schema validation, since it transforms rather than validates.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Activity is slowing. The repository last received commits 6 months ago.
- What is it written in?
- Mainly TypeScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- typestack/class-transformer7,335 ★ · -4
| Repository | 2026-09-23 | 2026-11-25 |
|---|---|---|
| typestack/class-transformer | 7.3k | 7.3k |
-4 Stars in the last 63 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The newest tag is five years old and the default branch is develop
The version history needs reading carefully. The most recent release is v0.5.1 from 2021-11-22, preceded by v0.5.0 and v0.4.1 both published on 2021-11-20, so the last three tags landed within two days and then nothing for years. The default branch is `develop` rather than `main`, and it was pushed to on 2026-05-22, so commits are still arriving without a release attached. The manifest still reports version 0.5.1, which means the published package and the branch you can read are not the same thing. For anyone pinning a dependency this is the practical question: what you install is a 2021 artifact, and what you read in the repository may be newer than what npm serves.
The problem is that JSON.parse returns plain objects
The readme frames everything around a distinction between two kinds of JavaScript object. Plain objects, also called literal objects and created with `{}`, are instances of the `Object` class. Class objects are instances of classes with their own constructor, properties and methods, usually defined with class notation. The problem appears when you load JSON from a backend or a file: after `JSON.parse` you hold plain objects, so annotating them as your class type lies to the compiler. Field access works and still type-checks, but the methods do not exist, which the readme shows with a class whose `getName()` and `isAdult()` methods cannot be called on the parsed result. The manual workaround is to build new instances and copy properties across, and the readme warns that this goes wrong quickly with a complex object hierarchy.
Six entry points, one of which keeps the old name
The fix is one call:
fetch('users.json').then((users: Object[]) => {
const realUsers = plainToInstance(User, users);
// now each user in realUsers is an instance of User classThe methods section lists six entry points: `plainToInstance`, `plainToClassFromExist`, `instanceToPlain`, `instanceToInstance`, `serialize`, and `deserialize` with a `deserializeArray` companion. Keeping `plainToClassFromExist` alongside `plainToInstance` is the sort of thing that tells you the API predates the TypeScript-first naming. Beyond conversion, the table of contents shows how much of the surface is about controlling output rather than mapping input: exposing getters and method return values, exposing properties under different names, skipping properties, skipping them only for particular operations, skipping all properties of a class, skipping private or prefixed ones, using groups to control exclusions, using versioning to control what is exposed, converting date strings into Date objects, working with arrays, additional data transformation in basic and advanced forms, other decorators, generics, and implicit type conversion.
reflect-metadata is a prerequisite in every environment
Installation is three steps on Node and three in a browser, and the second step is the one people miss. Alongside the package itself, the readme requires the `reflect-metadata` shim to be installed and imported in a global place such as the app entry module, with a bare import statement as the instruction. If you are on an old Node without ES6 features it also suggests an `es6-shim` import in the same global place. In a browser the shim is loaded with a script tag in the head of the HTML file pointing at the reflect-metadata file inside node_modules, and the readme notes that an Angular 2 project should already have it. The third browser step is for SystemJS users, where the package has to be registered in the `map` and `packages` configuration. The documentation also carries a section on how circular references are handled, and Angular 2 usage is shown in a plunker and a separate demo repository.
The default build emits CommonJS only
The manifest advertises four output formats and builds one of them by default. `main` points at a CommonJS build, `module` at an ES module build targeting es5, `es2015` at a newer module build, and `typings` at a types file. The build script, though, is just `npm run build:cjs`. The other formats are separate scripts: `build:es2015`, `build:esm5`, `build:types`, each invoking the TypeScript compiler with its own production tsconfig, and `build:umd`, which runs rollup against a rollup config instead. There are five production tsconfig files at the root, plus a spec configuration for tests. The package also declares `sideEffects: false`, which lets a bundler drop the import when nothing is used.
A pre-commit hook formats markdown as well as TypeScript
The tooling is conventional for the ecosystem and has one detail that surprises people. Husky runs lint-staged on commit, and lint-staged is configured for two patterns, TypeScript files and Markdown files, both routed to the prettier fix script. So editing the readme produces a formatting change in the same commit as your code. Linting is eslint over the source directory with warnings treated as errors, which is why the scripts carry a maximum warnings flag of zero, and there are separate fix and check variants. Tests run through jest with coverage and verbose output, a watch variant, and a continuous integration variant that runs in band with no cache. Coverage reporting has its own configuration file at the root, codecov.yml, and a badge at the top of the readme links to Codecov.
The samples directory contains a typo in a folder name
Five sample projects ship with the library. There is a simple usage sample, a sample for inheritance whose directory name is spelled with a missing n, a sample for custom arrays, one for generics, and one for a custom transformer. That last one is the reason the library is not merely a converter: a project can supply its own transformation logic rather than living with the built-in behaviour. The rest of the tree follows the same pattern, with a source directory, a test directory, a documentation directory configured through a GitBook file, a jest configuration, an eslint and a prettier configuration, a changelog and a package lock rather than a yarn or pnpm lock.
Editorial conclusion
The library fits a codebase whose models are real classes with behaviour on them and whose data arrives as parsed JSON, especially an API whose response shape needs explicit control. It does not fit a team that wants schema validation, since it transforms rather than validates. Before depending on it, note that the newest published tag is v0.5.1 from 2021-11-22 while the default branch is develop, decide which of those you are actually installing, and install reflect-metadata in the same entry point as your app.
Frequently asked questions
what is class transformer
It is a MIT licensed TypeScript library for decorator-based transformation, serialization and deserialization between plain JavaScript objects and class instances. plainToInstance turns parsed objects into real class instances so their methods exist, and instanceToPlain goes the other way for API output.
class transformer vs zod
The readme makes no comparison. It positions the library as mapping plain objects onto your classes and as tooling for controlling what your models expose in an API, through decorators for exposing, excluding, grouping and versioning properties. Nothing in it claims validation behaviour.
class transformer alternative
The readme names no alternative. The documented capability is converting with plainToInstance, plainToClassFromExist, instanceToPlain, instanceToInstance, serialize and deserialize, plus custom transformers in the sample directory, and it requires the reflect-metadata shim to be installed and imported globally.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/typestack-class-transformer)Star history chart for your README
[](https://hysenlabs.com/projects/typestack-class-transformer)Was this useful?