whatisgithub

What is class-transformer?

typestack/class-transformer — explained in plain English

Analysis updated 2026-06-24

7,330TypeScriptAudience · developerComplexity · 2/5Setup · easy

In one sentence

A TypeScript library that converts raw server data into proper class instances so you can call methods on them, and converts them back to plain objects for sending back to a server.

Mindmap

mindmap
  root((repo))
    What it does
      Convert raw objects
      Class instances
      Reverse conversion
    Features
      Field exclusion
      Versioning support
      Nested objects
    Tech Stack
      TypeScript
      Node.js
      Decorators
    Who it helps
      Backend devs
      Full stack devs
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Convert raw API response objects into typed class instances so you can call methods on them in your TypeScript application

USE CASE 2

Strip private or sensitive fields from user objects before returning them from a Node.js API endpoint

USE CASE 3

Handle nested objects and arrays in server responses with automatic type conversion using decorator annotations

What is it built with?

TypeScriptNode.js

How does it compare?

typestack/class-transformerbarvian/number-flowjakearchibald/idb
Stars7,3307,3347,326
LanguageTypeScriptTypeScriptTypeScript
Setup difficultyeasyeasyeasy
Complexity2/52/52/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 30min

Requires TypeScript with experimental decorators enabled in tsconfig.json.

So what is it?

class-transformer is a TypeScript library that solves a specific problem developers run into constantly: when your app fetches data from a server or reads from a file, the data arrives as raw JavaScript objects, not as the structured classes you defined in your code. Those raw objects look like they have the right fields, but they are missing any methods or behaviors your class definitions include. The library lets you convert raw data objects into proper class instances with a single function call. After the conversion, you can call methods on those objects the same way you would with anything you created directly in code. The reverse is also supported: you can take a class instance and flatten it back into a plain object, which is useful for sending data back to a server or saving to a file. Beyond basic conversion, the library provides detailed control over what gets included or excluded during a conversion. You can mark certain fields as private so they are never sent to clients, expose values computed by a method rather than a stored field, or group fields together so different parts of your app only see the data they need. Versioning support lets you include or exclude specific fields depending on which version of your API is being called. The library works on both server-side Node.js applications and in the browser. Configuration uses TypeScript decorators, which are annotations placed directly on class definitions to describe how each field should be treated during a conversion. The README contains detailed code examples for each feature, including how to handle nested objects, arrays, and circular references.

Copy-paste prompts

Prompt 1
I'm using class-transformer in a TypeScript Node.js app. My API returns a raw JSON user object but I need it as a User class instance so I can call methods on it. Show me how to define the class with decorators and use plainToInstance to convert the response.
Prompt 2
I have a TypeScript class with some fields that should never be sent to the client. Show me how to use class-transformer's @Exclude decorator to hide those fields when I call instanceToPlain.
Prompt 3
My API needs to support multiple versions where v1 returns fewer fields than v2. Show me how to use class-transformer's versioning support with @Expose to include or exclude fields based on the API version.

Frequently asked questions

What is class-transformer?

A TypeScript library that converts raw server data into proper class instances so you can call methods on them, and converts them back to plain objects for sending back to a server.

What language is class-transformer written in?

Mainly TypeScript. The stack also includes TypeScript, Node.js.

How hard is class-transformer to set up?

Setup difficulty is rated easy, with roughly 30min to a first successful run.

Who is class-transformer for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.