Reputation: 609
I'd like to create custom decorator with applyDecorators
imported from @nestjs/common
...
applyDecorators(
@Field(),
@MinLength(2)
)
...
But I got typescript lint errors. How can I create a custom decorator which wraps several decorators?
https://docs.nestjs.com/custom-decorators
"class-validator": "^0.11.0"
"@nestjs/common": "^7.0.9"
Upvotes: 4
Views: 7695
Reputation: 2096
You could define a custom decorator method using applyDecorators
method.
applyDecorators
method accepts PropertyDecorator
as arguments. so please make sure to convert them as PropertyDecorator
.
export const NameField = (options?: FieldOptions) =>
applyDecorators(
Field() as PropertyDecorator, // convert to PropertyDecorator
MinLength(2) as PropertyDecorator // convert to PropertyDecorator
)
)
Upvotes: 6