can I do this type defenition like in typescript with v validator?
I tried doing:
same as in typescript in my brain as doing this:
3 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.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
update: I created an object that has
keys and values
and the type seems to resemble what I want.
Yeah the best way of getting the validation you want is storing an array of objects with
key
and value
types (and then unpacking them into a record or map in your code if you prefer).
Fun fact -- TypeScript's Record
type has some kind of funky behavior when the key is a union of literals example
This is one of the reasons why we don't allow things like v.record(textData, <other validator>)
and just allow things like v.record(v.string(), <other validator>)
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.