Alvi
Alvi2mo ago

how to create tuples in convex

export const weekDayValidator = v.array( v.literal(WeekDay.SUNDAY), v.literal(WeekDay.MONDAY), v.literal(WeekDay.TUESDAY), v.literal(WeekDay.WEDNESDAY), v.literal(WeekDay.THURSDAY), v.literal(WeekDay.FRIDAY), v.literal(WeekDay.SATURDAY), ); i want to achieve this , but v.array only accepts 1 argument
4 Replies
Convex Bot
Convex Bot2mo ago
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!
lee
lee2mo ago
See this thread https://discord.com/channels/1019350475847499849/1300584211673255956/1300584211673255956 Although looking at your type, I'm not sure why you would want a tuple made entirely of literals. Do you perhaps want a v.union ?
sshader
sshader2mo ago
const v1 = v.union(v.literal("sunday"), v.literal("monday"), ...) would match values like "monday" and "wednesday". const v2 = v.array(v.union(v.literal("sunday"), v.literal("monday"), ...)) would match values like ["monday"] and ["saturday", "sunday"] and ["monday", "monday", "tuesday"] (but not "monday" since it's not an array, or ["monday", "foo"] since "foo is not in the union)
lee
lee2mo ago
the weekDayValidator from the original question, if it worked, would match exactly ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"] and no other values, which doesn't sound particularly useful

Did you find this page helpful?