Kind: Interface
Source: packages/common/serializer/class-serializer.interfaces.ts
Part of: Common
ClassSerializerContextOptions provides serializer context metadata for class-based transformation operations. Its type field identifies the target constructor, allowing the serializer to resolve class-specific serialization behavior and metadata.
Properties
| Property | Type |
|---|---|
type | Type<any> |
Diagram
mermaidgraph LR A[Serialization Request] --> B[ClassSerializerContextOptions] B --> C[type: Type<any>] C --> D[Target Class Constructor] D --> E[Class Serialization Metadata] E --> F[Serialized Output]
Usage
tsimport { ClassSerializerContextOptions, Type } from '@nestjs/common';
class UserDto {
id: number;
email: string;
}
const serializerOptions: ClassSerializerContextOptions = {
type: UserDto as Type<UserDto>,
};
// Pass the options to serializer-related infrastructure
function serializeWithContext(options: ClassSerializerContextOptions) {
return options.type;
}
const targetType = serializeWithContext(serializerOptions);
AI Coding Instructions
- Set
typeto the constructor of the class whose serialization metadata should be used. - Use Nest's
Type<T>type when declaring or passing class constructors. - Do not pass an instance (for example,
new UserDto()); provide the class reference (UserDto) instead. - Integrate this interface where serializer logic needs explicit target-type information, especially when runtime type inference is unavailable.
Was this page helpful?