#How to use parameter decorator when developing with js

5 messages · Page 1 of 1 (latest)

solar flax
#

Now I use js for development, such as writing a file upload interface. Using function decorators will cause babel compilation to fail.

onyx vault
#

Like all other parameter decorators when using babel and raw JS, you need to use @Bind().
Typescript Example:

@Get(':id')
findOne(@Param() params: any): string {
  console.log(params.id);
  return `This action returns a #${params.id} cat`;
}

Equivalent JS example:

@Get(':id')
@Bind(Param())
findOne(params) {
  console.log(params.id);
  return `This action returns a #${params.id} cat`;
}

So, in your case, to bind @UploadedFile() and @Req() you need to do @Bind(UploadedFile(), Req())

solar flax
onyx vault
#

It's just extrapolation of what already exists. If @Body() can be used with @Bind(Body()) it makes sense that @UploadedFile() would be used in the same way