Gorka CesiumG
Convex Community16mo ago
7 replies
Gorka Cesium

How to assign types created with convex/values to function parameters?

I want to create a utility function but need to pass an argument that has type safety.

How can I reuse the type from a convex/values into a normal function?

Example

schema.ts


export const cut = v.union(v.literal("Rect"), v.literal("Curve");


export default defineSchema({
  things: defineTable({
    cut: cut
  })
})


Here I have my utility function. I can use some hacks around it but the compiler won't know when the cut definition changed.

utils.ts
export let cutToText = (cut: any) => {
  return cut === "Rect" ? "Rectangle": cut === "Curve" ? "Curvy" : ""
}
Was this page helpful?