-
Notifications
You must be signed in to change notification settings - Fork 119
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
TypeError at formatI18nErrors when validating nested array of objects #633
Comments
Hi there, is there someone who can help me with this issue? Best regards, |
Hello there ! I also had this issue. By following the stack trace and inspecting the code I found the source of the problem in this function: // src/utils/util.ts, function definition starts at line 55
// ...
export function formatI18nErrors<K = Record<string, unknown>>(
errors: I18nValidationError[],
i18n: I18nService<K>,
options?: TranslateOptions,
): I18nValidationError[] {
return errors.map((error) => {
error.children = formatI18nErrors(error.children ?? [], i18n, options);
// the error is in the next line
error.constraints = Object.keys(error.constraints).reduce((result, key) => {
const [translationKey, argsString] = error.constraints[key].split('|');
const args = !!argsString ? JSON.parse(argsString) : {};
const constraints = args.constraints
? args.constraints.reduce((acc: object, cur: any, index: number) => {
acc[index.toString()] = cur;
return acc;
}, {})
: error.constraints;
result[key] = i18n.translate(translationKey as Path<K>, {
...options,
args: {
property: error.property,
value: error.value,
target: error.target,
contexts: error.contexts,
...args,
constraints,
},
});
return result;
}, {});
return error;
});
}
// ...
The solution I found is to replace But obviously without a fix in the repo nothing will change when fetching from npm |
Hi there,
I always get a TypeError: Cannot convert undefined or null to object\n when using validation method "i18n.validate" from the "I18nService" while validating nested array of objects.
This error does not occur, when the normal "validate" function of the "class-validator" library is used.
Thank you,
Heiko
My Dto (Parent)
My Dto (Nested)
My Pipe
Stack Trace
Originally posted by @heken84 in #630
The text was updated successfully, but these errors were encountered: