#Does v.any() validation accepts objects with object field values (aka nested objects) ?
2 messages · Page 1 of 1 (latest)
v.any() accepts any Convex value, not truly “any JS value”. Convex values must themselves be made only of supported types: null, number, boolean, string, bigint, ArrayBuffer, arrays, and plain objects whose values are also Convex values, recursively. [Value; Supported types]
Your error:
Email { "value": "[email protected]" } is not a supported Convex type
means that the runtime encountered a value whose runtime type is Email, not a “plain old JavaScript object”. Convex only supports plain objects without a custom prototype. [Data types]
So:
- Yes,
v.any()will accept nested objects, as long as they are plain objects made from supported Convex values. - It will not accept class instances or other objects with custom prototypes (like
new Email(...)).
To fix this, convert those nested values to plain data before passing them to Convex, for example:
// Instead of an Email instance:
{ email: new Email("[email protected]") }
// Use a plain object or string:
{ email: "[email protected]" }
// or
{ email: { value: "[email protected]" } }