Kind: Interface
Source: packages/core/services/reflector.service.ts
Part of: Core
CreateDecoratorOptions configures how a reflector decorator reads and transforms metadata values. It defines the metadata key to access and a transform function that converts the raw parameter value into the type consumed by the decorator or reflector service.
Properties
| Property | Type |
|---|---|
key | string |
transform | (value: TParam) => TTransformed |
Diagram
mermaidgraph LR A[Decorator Invocation] --> B[CreateDecoratorOptions] B --> C[key: string] B --> D[transform(value)] C --> E[Reflector Metadata Lookup] E --> F[Raw Metadata Value] F --> D D --> G[Transformed Metadata Value]
Usage
tsimport type { CreateDecoratorOptions } from '@nestjs/core/services/reflector.service';
interface RoleOptions {
roles: string[];
}
const roleDecoratorOptions: CreateDecoratorOptions<
string[],
RoleOptions
> = {
key: 'roles',
transform: (roles) => ({
roles: roles.map((role) => role.toLowerCase()),
}),
};
// The transform function receives the raw metadata value and returns
// the normalized value used by the application.
const normalizedRoles = roleDecoratorOptions.transform(['ADMIN', 'EDITOR']);
// { roles: ['admin', 'editor'] }
console.log(normalizedRoles);
AI Coding Instructions
- Use a stable, unique
keystring that matches the metadata key used by the associated decorator. - Keep
transformpure: it should convert the input value without mutating it or relying on external state. - Type
TParamto match the raw decorator input andTTransformedto match the value consumers should receive. - Validate or normalize optional, array, and nested values inside
transformwhen downstream code expects a consistent shape. - Ensure metadata readers use the same key and expect the transformed output type rather than the raw decorator argument.
Relationships
- IMPORTS →
CustomDecorator - IMPORTS →
SetMetadata - IMPORTS →
Type - IMPORTS →
isEmpty - IMPORTS →
isObject
Was this page helpful?