【发布时间】:2020-08-07 05:56:45
【问题描述】:
假设我有这个基于文档中的示例的课程 (https://github.com/typestack/class-validator#usage)
import {MinLength, MaxLength, validate} from "class-validator";
export class Post {
@IsString()
body: strong;
@IsString()
title: string;
//...many more fields
public async validate(){
validate(this, { forbidUnknownValues: true, validationError: { target: false } });
}
}
我创建了这个类的一个实例并为字段赋值。
const post = new Post()
post.body = 'body'
post.title = 'title'
// ... assign all the other fields
我想验证post,跳过除title 之外的所有字段的验证。除了将组分配给所有字段之外,似乎没有办法做到这一点,我不想这样做。有没有办法只验证这个单一的字段?
【问题讨论】:
标签: typescript class-validator