nest icon indicating copy to clipboard operation
nest copied to clipboard

Route params decorators bug in ES

Open cdiaz opened this issue 9 years ago • 16 comments

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

cdiaz avatar Jun 24 '17 15:06 cdiaz

I am experiencing this as well.

benbayard avatar Jun 25 '17 22:06 benbayard

@kamilmysliwiec any known bugs here or workarounds?

benbayard avatar Jun 30 '17 18:06 benbayard

Hi @benbayard, @cdiaz,

Unfortunately, babel doesn't support custom parameters decorators.. This is why it's not working without TypeScript :disappointed:

kamilmysliwiec avatar Jul 05 '17 20:07 kamilmysliwiec

I don't think I'm using babel though. I'm just using ts-node. Could I have something incorrect in my tsconfig?

benbayard avatar Jul 05 '17 21:07 benbayard

@benbayard, it should work fine with ts-node. Could you share us your entire controller as an example?

kamilmysliwiec avatar Jul 06 '17 06:07 kamilmysliwiec

@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 avatar Jul 06 '17 16:07 benbayard

@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 avatar Jul 06 '17 18:07 cdiaz

@cdiaz show your babel config

cojack avatar Jul 07 '17 10:07 cojack

@cojack This same

cdiaz avatar Jul 07 '17 12:07 cdiaz

@cdiaz why you close the issue? it's fixed, did you found solution?

cojack avatar Jul 13 '17 04:07 cojack

@cojack, i'm afraid there's no solution. The params decorators are the TypeScript feature.

kamilmysliwiec avatar Jul 16 '17 12:07 kamilmysliwiec

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 avatar Sep 16 '17 21:09 thomrick

@ThomRick the implementation is different, it won't work :disappointed:

kamilmysliwiec avatar Sep 18 '17 06:09 kamilmysliwiec

Hi @cdiaz, Now Nest is compatible with pure JavaScript + Babel now :slightly_smiling_face: You can find examples in the docs.

kamilmysliwiec avatar Oct 09 '17 21:10 kamilmysliwiec

n find examples in the docs. Could you provide a link to the examples?

mathis-m avatar Jun 19 '19 11:06 mathis-m

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[bot] avatar Sep 23 '19 15:09 lock[bot]