d7037675创建于 2021年8月11日历史提交
import Schema, {
  ValidateCallback,
  ValidateFieldsError,
  Values,
} from '../src/index';

const callback: ValidateCallback = (errors, fields) => {
  if (errors === null) {
    const f: Values = fields;
    console.log('transformed values:', JSON.stringify(f));
  } else {
    const f: ValidateFieldsError = fields;
    console.log('validate error:', JSON.stringify(f));
  }
};

new Schema({
  v: {
    required: true,
    type: 'array',
    defaultField: [{ type: 'number', max: 0, transform: i => Number(i) }],
  },
}).validate(
  {
    v: ['1', '2'],
  },
  callback,
);