Route params decorators not working properly in ES
I'm trying to use @Body decorator, but I'm getting unwanted results:
@Post('/signup')
async signUp (
@Request() req,
@Response() res,
@Body('username') username,
@Body('password') password ) {
console.log(username) //[Function: next]
console.log(password) //undefined
}
Then I tried to send the @Body decorator arguments first, but when printing them I got equivalents to the Request, Response and Next in their respective order.
@Post('/signup')
async signUp (
@Body('username') username,
@Body('password') password,
@Request() req,
@Response() res
) {
console.log(username) //IncomingMessage {......... <- req equivalent
console.log(password) //ServerResponse {...... <- res equivalent
console.log(req) //[Function: next] <- next equivalent
console.log(res) //undefined
}
I think the problem is with the order or obligation of the params
I am experiencing this as well.
@kamilmysliwiec any known bugs here or workarounds?
Hi @benbayard, @cdiaz,
Unfortunately, babel doesn't support custom parameters decorators.. This is why it's not working without TypeScript :disappointed:
I don't think I'm using babel though. I'm just using ts-node
. Could I have something incorrect in my tsconfig?
@benbayard, it should work fine with ts-node
. Could you share us your entire controller as an example?
@kamilmysliwiec I was actually just able to solve the issue I was having by using target: es6
@cdiaz can you check if this works for you?
@benbayard Apparently you are using TypeScript, in my case I am using Babel, like this:
https://github.com/kamilmysliwiec/nest-babel-starter.
Therefore tsconfig does not apply in this case
@cdiaz show your babel config
@cojack This same
@cdiaz why you close the issue? it's fixed, did you found solution?
@cojack, i'm afraid there's no solution. The params decorators are the TypeScript feature.
Hey guys !
Did you try this ?
https://www.npmjs.com/package/babel-plugin-transform-function-parameter-decorators
I'll try this soon if no one do ;-)
@ThomRick the implementation is different, it won't work :disappointed:
Hi @cdiaz,
Now Nest is compatible with pure JavaScript + Babel now :slightly_smiling_face: You can find examples in the docs.
n find examples in the docs.
Could you provide a link to the examples?
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.
Most helpful comment
Hi @cdiaz,
Now Nest is compatible with pure JavaScript + Babel now :slightly_smiling_face: You can find examples in the docs.