Describe the bug
In 0.28.1, these 2 signatures work:
string.matches(regex: Regex, message?: string | function): Schemastring.matches(regex: Regex, options: { message: string, excludeEmptyString: bool }): SchemaIn 0.28.2:
The first one throws an error.
Cannot use 'in' operator to search for 'excludeEmptyString' in <message>
The bug has been introduced here: https://github.com/jquense/yup/commit/27e5d684acb7563fa44c4da6baa8e81c94a08c34#diff-57c5960218f1091895b3610a7d779378R79
If options is a string, we cannot make this operation 'excludeEmptyString' in options.
To Reproduce
const schema = yup.string().matches(/test/, 'My message')
await schema.isValid('hi')
Expected behavior
Should not throw an error
I am also the same issue with 0.28.2
TypeError: Cannot use 'in' operator to search for 'excludeEmptyString' in ${path} must be a website address
StringSchema.matches
node_modules/yup/es/string.js:93
90 | var name;
91 |
92 | if (options) {
> 93 | if (options.message || 'excludeEmptyString' in options || options.name) {
| ^ 94 | excludeEmptyString = options.excludeEmptyString;
95 | message = options.message;
96 | name = options.name;
Seeing this too
I faced the same error after I updated yup to 0.28.2.
Same problem for me, rollback in 0.28.1 solve the problem
I also had this error. The function expects an object, but a string is passed to it and therefore an error message is given. A rollback fixed the issue also for me, but I also made this pull request #801 for a suggested fix.
Most helpful comment
I also had this error. The function expects an object, but a string is passed to it and therefore an error message is given. A rollback fixed the issue also for me, but I also made this pull request #801 for a suggested fix.