Gorka Cesium
Gorka Cesium8mo ago

recursive type

I'm trying to declare a dynamic tree structure for layouts (similar to HTML). Is it possible to have a recursive type? I'm trying this
let element_eurofutur = v.union(v.literal("Row"), v.literal("Col"), v.literal("Hoja"), v.literal("Fijo"), v.literal("Poste") );

let node_eurofutur = v.object({
element: element_eurofutur,
children: v.array(node_eurofutur)
});
let element_eurofutur = v.union(v.literal("Row"), v.literal("Col"), v.literal("Hoja"), v.literal("Fijo"), v.literal("Poste") );

let node_eurofutur = v.object({
element: element_eurofutur,
children: v.array(node_eurofutur)
});
but getting error
Block-scoped variable 'node_eurofutur' used before its declaration.
5 Replies
Michal Srb
Michal Srb8mo ago
I don't think Convex validators support this currently.
Gorka Cesium
Gorka CesiumOP8mo ago
ok i'm thinking as a plan B i can use a string as an emmet notation and hydrate it on the client side or not sure if Convex validators support JSON any as a type
Michal Srb
Michal Srb8mo ago
You store pretty much any JSON in Convex directly with v.any(). You can even pretend the type is checked with v.any() as Validator<MyType> But the validation will be up to you at your callsites.
Michal Srb
Michal Srb8mo ago
Using branded types in validators
If you have a more specific type than what you can express with Convex validators, you can still document that at the type level in Convex by casting ...
Gorka Cesium
Gorka CesiumOP8mo ago
sounds good, that might work

Did you find this page helpful?