#Validatation pipe typechecking ?

6 messages · Page 1 of 1 (latest)

potent halo
#

In the following example, copied from the nestjs doc and slightly modified so that the 'id' param is a string :

  @Get(':id')
  async findOne(@Param('id', ParseIntPipe) id: string) {
    return id;
  }

Why does that @tawny vale decorator lets me use a validation that return a number and doesn't complain ?

Is there some config to enable this ?

Thank you !

solemn solstice
#

Because it is not a validator this is the transformer - ParseIntPipe.

winged tartan
#

Decorators also can't enforce types. It's a typescript limitation

potent halo
solemn solstice
#

So do not use a transform pipe at all. At the start it is string.

winged tartan
#

Again, that's a Typescript limitation. You should be mindful of that and catch it in code review