Validación en NestJS
class-validator integra nativo con NestJS via ValidationPipe. Zod es más flexible para validar JSON crudo y compartir schemas con el frontend.
class-validator
typescriptexport class CreatePostDto { @IsString() @MinLength(3) title: string; @IsDateString() date: string; }
Zod
typescriptconst createPostSchema = z.object({ title: z.string().min(3), date: z.string().datetime(), }); type CreatePost = z.infer<typeof createPostSchema>;
Mi regla: DTOs internos de NestJS con class-validator; contratos compartidos con frontend con Zod.
¿Te sirvió este post?
Discusión
2 comentariosJG
Juana GómezHace 2 horas
Excelente desglose. La explicación del Request scope me vino al pelo.
¿Te gustó el artículo?
Suscribite para recibir las últimas publicaciones directo en tu email.