parameter icon indicating copy to clipboard operation
parameter copied to clipboard

可以用typescript的interface来设置rule

Open forthedamn opened this issue 8 years ago • 0 comments

一般写ts的时候会先申明一个interface(这个interface只能够解决ts编译前的校验),可以利用这个interface来生成rule,校验运行时的参数,比如对一个request做参数校验:

interface ParamRequest {
  id: number,
  page: string,
  hehe: boolean,
  haha: Array<string>,
}

let rule: ParamRequest;

const param: ParamRequest = this.request.body;

const isError = this.validate.validator(rule,  param);

forthedamn avatar Dec 30 '16 03:12 forthedamn