JamalJ
Convex Community11mo ago
5 replies
Jamal

How can I infer typescript interfaces into a validator?

Example: I have a type called dog:
interface Dog {
 name: string
}

and I have a convex mutation:
const createDog = mutation({
  args: {
  dog: {
    name: v.string()
  }
},
  handler(ctx, args) { ... }
})


in this example I have to manually type out the
args
using convex values even though I have a typescript interface. Can I create an inferred validator type based on my own interfaces to avoid code duplication?

it would be useful to do something like:
const createDog = mutation({
  args: {
  dog: inferAsValidator<Dog>
},
  handler(ctx, args) { ... }
})
Was this page helpful?