drizzle-zod insert/update schema refinements type

I usually want to apply same refinements to insert and update. To avoid duplication I want to define them in an object. How can I type it properly so that it knows the type of the schema arguments, etc.?

type TableRefinements = ...

const refinements: TableRefinements = {
  foo: (schema) => schema.trim(),
} as const;

createInsertSchema(table, refinements)


Tried unsuccessfully to extract from createInsertSchema() parameters, but I think it may be matching the first signature with a single generic , in which the second parameter is undefined:

type TableRefinements = Parameters<typeof createInsertSchema<typeof table>>[1] // tuple has no element at index '1'


Much appreciated!
Was this page helpful?