#Does v.any() validation accepts objects with object field values (aka nested objects) ?

2 messages · Page 1 of 1 (latest)

real gobletBOT
#

Hi @stuck sky. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

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]" } }

as long as those objects are plain JSON-like objects.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: