API Reference
class-transformer
Transforms plain objects into typed class instances and back, with Type and Transform decorators.
Official Documentation ↗CompatibilityThis documentation covers version
v0.5. Check the official docs for the latest API surface.Installation
npm
npm install class-transformerMethods
No methods match this filter.
class-transformer bridges JSON payloads and class instances so methods and types are available after parsing.
Key Features
- plainToInstance and instanceToPlain
- Type and Transform decorators
- Exclude and expose strategies
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
API reference evidence
Fetched from official sources on 2026-11-08T09:38:08.940Z via WebFetch https://raw.githubusercontent.com/typestack/class-transformer/master/src/index.ts; WebFetch https://raw.githubusercontent.com/typestack/class-transformer/master/src/decorators/type.decorator.ts.
plainToInstance→ signature from https://raw.githubusercontent.com/typestack/class-transformer/master/src/index.ts; official text: “export function plainToInstance<T, V>(cls: ClassConstructor, plain: V, options?: ClassTransformOptions): T; /** * Converts plain (literal) object to class (constructor) object. Also works with arrays. */” instanceToPlain→ signature from https://raw.githubusercontent.com/typestack/class-transformer/master/src/index.ts; official text: “export function instanceToPlain(object: T, options?: ClassTransformOptions): Record<string, any>; /** * Converts class (constructor) object to plain (literal) object. Also works with arrays. */” @Type→ signature from https://raw.githubusercontent.com/typestack/class-transformer/master/src/decorators/type.decorator.ts; official text: “export function Type( typeFunction?: (type?: TypeHelpOptions) => Function, options: TypeOptions = {} ): PropertyDecorator /** * Specifies a type of the property. * The given TypeFunction can return a constructor. A discr”
FAQ
- Why are nested objects still plain?
- The transformer can only instantiate classes it knows about. Add @Type(() => Child) to nested properties so they are converted too.
- How do I exclude sensitive fields?
- Use @Exclude() together with excludeExtraneousValues or explicit @Expose() annotations so only intended fields are serialized.
- Does it validate values?
- No. It converts shapes only. Combine it with class-validator when you need constraint checking.
Report a problem with this API docOpens a pre-filled issue on GitHub.