prefix validator keys helper 🙏
I'm playing around with this code:
The part that uses regular TS types works, but I'm having issues with the validators part, namely
prefixValidatorKeys
. Any idea of how this could be implemented?9 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Ask in the <#1228095053885476985> channel to get a response from <@1072591948499664996>.
- Avoid tagging staff unless specifically instructed.
Thank you!
You can use the new v.record()
with v.record I can't set different keys to different types, so don't think that would work...
You mean you want the better return type for
prefixValidatorKeys
? I think you'd return something like VObject
with a similar mapped type to PrefixProperties
. The Object.fromEntries
with map
will lose specific types unfortunatelyyeah, that's the issue I'm running into with these bulk operations.. I'm trying to do something like this with validators as well but I think I might run into the same limitation?
Yeah I've found it's sometimes easier to tell TypeScript the end state with a return type, then just do the convenient JS with an occasional
any
, when the types are hard for TypeScript to keep up with. In general I feel like the TS types for .map
and Object.*
are lacking. So doing something like this for me works:
And if you want the hover description to also have the prefixes shown, you can use Expand
:
thanks Ian, that solved the issue with prefixing. For the makeAllOptional helper I realized that in Zod you can just do .partial() on an object. Is there something similar for Convex validators?
There's a
partial
helper I put in convex-helpers/validators.True