Convert raw API response objects into typed class instances so you can call methods on them in your TypeScript application
Strip private or sensitive fields from user objects before returning them from a Node.js API endpoint
Handle nested objects and arrays in server responses with automatic type conversion using decorator annotations
Requires TypeScript with experimental decorators enabled in tsconfig.json.
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.
← typestack on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.