我正在尝试使用 TS、React 创建我的 ValidationSchemas,以便以 Formik 形式使用它们。
我的模块中有多个验证模式需要遵守,所以我想创建一个枚举,以便轻松重用它们。
在 TS 文件中:
import * as Yup from "yup";
export const ValidationSchema {
AddUserSchema = Yup.object().shape({
username: Yup.string('Provide a username').required('Username is required'),
email: Yup.string().email('Provide a valid email address'),
password: Yup.string('Provide a password').required('Password is required'),
confirmPassword: Yup.string('Provide your password again')
.required('Password confirmation is required')
.oneOf([Yup.ref('password')], 'Passwords do not match'),
group: Yup.string('Please select a group').required('Group is required')
}),
EditUserSchema = Yup.object().shape({
username: Yup.string('Provide a username').required('Username is required'),
email: Yup.string().email('Provide a valid email address'),
group: Yup.string('Please select a group').required('Group is required')
}),
EditPasswordSchema = Yup.object().shape({
password: Yup.string('Provide a password').required('Password is required'),
confirmPassword: Yup.string('Provide your password again')
.required('Password confirmation is required')
.oneOf([Yup.ref('password')], 'Passwords do not match'),
}),
}
但是我在每个 Yup.String 中都遇到错误,也就是说:
Expected 0 arguments, but got 1.ts(2554)
const string: Yup.StringSchemaConstructor
() => Yup.StringSchema
我试图找到对 Yup 类型的引用,但没有运气。这里有什么问题。我需要向 Yup 传递一个参数,它说,预期为 0。对我来说没有意义。谢谢你的时间!