You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you use NestJs (https://nestjs.com/) then these rules will help keep you usage of decorators consistent.
38
+
If you use NestJs (https://nestjs.com/) then these rules will help you to prevent common bugs and issues. They mostly check that you are using decorators correctly.
37
39
38
40
See the following summaries
39
41
@@ -101,13 +103,123 @@ Note: You can easily turn off all the swagger rules if you don't use swagger by
101
103
// more config
102
104
```
103
105
106
+
Disable a single rule with the full name e.g. in your eslint configuration...
If you use any of the class validator decorators on a property that is not a primitive, you should tell class-transformer how to transform it into a class first.
164
+
165
+
This PASSES because we're validating a Person class and we have added the @Type decorator.
166
+
167
+
```ts
168
+
exportclassCreateOrganisationDto {
169
+
@ApiProperty({type: Person, isArray: true})
170
+
@IsDefined()
171
+
@Type(() =>Person)
172
+
members!:Person;
173
+
}
174
+
```
175
+
176
+
This PASSES because it is a primitive type (boolean, string, number). We don't need to tell class-transformer how to transform those.
177
+
178
+
```ts
179
+
exportclassCreateOrganisationDto {
180
+
@ApiProperty({type: Person, isArray: true})
181
+
@ValidateNested({each: true})
182
+
@IsBoolean()
183
+
members!:boolean;
184
+
}
185
+
```
186
+
187
+
This PASSES because we only check properties that have a class-validator decorator (e.g. `@IsDefined()`)
188
+
189
+
```ts
190
+
exportclassCreateOrganisationDto {
191
+
@ApiProperty({type: Person, isArray: true})
192
+
members!:Person|Date;
193
+
}
194
+
```
195
+
196
+
This FAILS because you should always tell class-transformer the type for an array
197
+
198
+
```ts
199
+
exportclassCreateOrganisationDto {
200
+
@ApiProperty({type: Person, isArray: true})
201
+
@ValidateNested({each: true})
202
+
@IsArray()
203
+
members!: (Person|Date)[];
204
+
}
205
+
```
206
+
207
+
This FAILS because Date is not a primitive type (string, number, boolean)
0 commit comments