I previously saw these two syntaxes for UsePipes Decorator in NestJS tutorials:
@UsePipes(ValidationPipe)
@UsePipes(new ValidationPipe())
From what I understand, ValidationPipe is a class itself, where new ValidationPipe() just works as in all object-oriented languages and creates a new instance of ValidationPipe.
What should I use ? What is the difference ? Is there any special usage where one if preferable to another ?
Both work fine as is. If you need to pass any options to the pipe though, you should use the new ValidationPipe(). Otherwise, Nest will see the pipe is a class reference, not an instance, and create the instance to be used.