Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Decorators not being treated in the same fashion as built in ones #765

Closed
lvalencia opened this issue Jun 6, 2018 · 3 comments
Closed

Comments

@lvalencia
Copy link

lvalencia commented Jun 6, 2018

I'm submitting a...


[ ] Regression 
[x] Bug report
[] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Custom Decorators not being treated in the same fashion as built in ones

Expected behavior

Custom Decorators be treated in the same fashion as built in ones
https://docs.nestjs.com/custom-decorators
Nest treats a custom param decorators in the same fashion as the built-in ones (@Body(), @Param() and @Query()). It means that pipes are executed for the custom annotated parameters as well (in this case, for the user argument). Moreover, you can apply the pipe directly to the custom decorator:

makes it sound like they are treaded the same but arent

Minimal reproduction of the problem with instructions

Create a custom Decorator, Create a Pipe, try to get the Pipe to be instantiated and dependency injected.

@MyCustomDecorator(MyCustomPipeTransform) output

it wont run the pipe

or

@MyCustomDecorator('data', MyCustomPipeTransform) output

it throws compilation errors

What is the motivation / use case for changing the behavior?

It is a reasonable expectation for that to work, but when you dig into the signatures you can see that it wont do the dependency injection for you

export declare function createParamDecorator(factory: CustomParamFactory): (data?: any, ...pipes: PipeTransform<any>[]) => ParameterDecorator;
export declare function Param(): any;
export declare function Param(...pipes: (Type<PipeTransform> | PipeTransform)[]): any;
export declare function Param(property: string, ...pipes: (Type<PipeTransform> | PipeTransform)[]): any;

Environment

[System Information]
OS Version     : macOS Sierra
NodeJS Version : v9.11.1
NPM Version    : 6.1.0
[Nest Information]
microservices version : 5.0.0
websockets version    : 5.0.0
swagger version       : 2.0.0
testing version       : 5.0.0
common version        : 5.0.0
core version          : 5.0.0
@lvalencia
Copy link
Author

lvalencia commented Jun 6, 2018

Update:

It's a type definitions issue. If anyone needs a work-around you can do this

@MyCustomDecorator('your data (if any)', MyCustomPipeTransform as any) output

it will dependency inject for you.

@kamilmysliwiec
Copy link
Member

Fixed in v5.1.0

@lock
Copy link

lock bot commented Sep 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants