Redundant typing
Hey noob question here
I have a table definition here :
as you can see, I define the type of price here. In another file :
As you can see I am also defining types of args here, and setting values accordingly in "insert" part.
My question is : since I'm already defining types when doing the tables, can I use these types in the args ? so that I don't have to copy/paste types between table and args ?
8 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!
There is
schema.tables.whatever.validator.fields
You could do something like
or if you want to take any of them (eg for upsert)
Here's a real example if it helps
I'm trying this but I think I'm mistaken
is your schema the
defineSchema from schema.ts ?
but yeah since in Convex "everything is Typescript", I suppose what you are suggesting should work one way or another for my codebase
from
convex/schema.ts -> export default defineSchema({...})
then in other files like convex/auth.ts just import schema from "./schema";@Oscar
CHeck out this article: https://stack.convex.dev/argument-validation-without-repetition
Referenced in convex helpers: https://www.npmjs.com/package/convex-helpers#validator-utilities
Argument Validation without Repetition
A few more advanced techniques & helpers to further reduce duplication and accelerate your Convex workflow.
npm
convex-helpers
A collection of useful code to complement the official convex package.. Latest version: 0.1.104, last published: 6 days ago. Start using convex-helpers in your project by running
npm i convex-helpers. There are 18 other projects in the npm registry using convex-helpers.thank you!!
!!!!!