Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #299 prevent reduce to throw error #300

Merged
merged 2 commits into from
Dec 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions yup/src/yup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,31 @@ const parseErrorSchema = (
error: Yup.ValidationError,
validateAllFieldCriteria: boolean,
) => {
return error.inner.reduce<Record<string, FieldError>>((previous, error) => {
if (!previous[error.path!]) {
previous[error.path!] = { message: error.message, type: error.type! };
}
return (error.inner || []).reduce<Record<string, FieldError>>(
(previous, error) => {
if (!previous[error.path!]) {
previous[error.path!] = { message: error.message, type: error.type! };
}

if (validateAllFieldCriteria) {
const types = previous[error.path!].types;
const messages = types && types[error.type!];
if (validateAllFieldCriteria) {
const types = previous[error.path!].types;
const messages = types && types[error.type!];

previous[error.path!] = appendErrors(
error.path!,
validateAllFieldCriteria,
previous,
error.type!,
messages
? ([] as string[]).concat(messages as string[], error.message)
: error.message,
) as FieldError;
}
previous[error.path!] = appendErrors(
error.path!,
validateAllFieldCriteria,
previous,
error.type!,
messages
? ([] as string[]).concat(messages as string[], error.message)
: error.message,
) as FieldError;
}

return previous;
}, {});
return previous;
},
{},
);
};

export const yupResolver: Resolver =
Expand Down