kstulgys
kstulgys5mo ago

How do I define a more complex object with convex values?

is there a way to define object like:
type Product = { ... }

Record<string,Product>

// string is product id (_id)
type Product = { ... }

Record<string,Product>

// string is product id (_id)
I know this is incorrect:
v.object({
[v.id("products")]: v.object({...})
})
v.object({
[v.id("products")]: v.object({...})
})
2 Replies
Michal Srb
Michal Srb5mo ago
v.record is not supported yet. We'll likely add a v.record for this in the future. For now the best work around is: v.array(v.object({key: string, value: ....})) or use v.any() as Validator<Record<string, Product>> and rely on TypeScript for now.
kstulgys
kstulgysOP5mo ago
thank you

Did you find this page helpful?