用typescript注解的方式实现接口参数validate。
发布于 6 年前 作者 luluzero 2907 次浏览 来自 分享

直接上代码

import { IsString, IsInt, IsOptional, IsNotEmpty } from 'class-validator';

export class LoginReq {

  @IsString()
  @IsNotEmpty()
  username: string;

  @IsString()
  @IsNotEmpty()
  password: string;

}
2 回复

他家的 class-transformer 也不错

来自酷炫的 CNodeMD

@yviscool 是的,配合起来用很爽。

回到顶部