Skip to content

Commit c930159

Browse files
Merge pull request #1884 from roim/patch-1
docs: Add ValidationPipe hint on not using `import type` for DTOs
2 parents 224e437 + ad27312 commit c930159

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

content/techniques/validation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ create(@Body() createUserDto: CreateUserDto) {
121121

122122
> info **Hint** Since TypeScript does not store metadata about **generics or interfaces**, when you use them in your DTOs, `ValidationPipe` may not be able to properly validate incoming data. For this reason, consider using concrete classes in your DTOs.
123123
124+
> info **Hint** When importing your DTOs, you can't use a type-only import as that would be erased at runtime, i.e. remember to `import {{ '{' }} CreateUserDto {{ '}' }}` instead of `import type {{ '{' }} CreateUserDto {{ '}' }}`.
125+
124126
Now we can add a few validation rules in our `CreateUserDto`. We do this using decorators provided by the `class-validator` package, described in detail [here](https://github.com/typestack/class-validator#validation-decorators). In this fashion, any route that uses the `CreateUserDto` will automatically enforce these validation rules.
125127

126128
```typescript

0 commit comments

Comments
 (0)