我在更新版本 16 到 18 中编写的一些旧 ReactJs 代码时遇到困难,同时 Yup 包也被更新(0.26.6 -> 1.2.0),因为它的一些语法规则似乎已更改,并且我遇到奇怪的错误,我无法诊断和修复。
import helpers from '../../../Shared/validationHelpers';
const { domainName } = helpers.regEx;
export default Yup.object({
enabled: Yup.boolean(),
hostname: Yup.string().when('enabled', {
is: true,
then: Yup.string()
.matches(domainName, 'Please provide a fully qualified domain name')
.required('You must provide a hostname'),
otherwise: Yup.string().notRequired(),
}),
});
Run Code Online (Sandbox Code Playgroud)
Helpers 只是一个带有一堆正则表达式定义的文件,domainName 是用于设置域名的正则表达式。
错误发生在“is: true”上:
No overload matches this call.
Overload 1 of 4, '(keys: string | string[], builder: ConditionBuilder<StringSchema<string, AnyObject, undefined, "">>): StringSchema<string, AnyObject, undefined, "">', gave the following …Run Code Online (Sandbox Code Playgroud)