arktypea
arktype9mo ago
noah

Generic wrapper for drizzle-arktype functions

When using the drizzle-arktype functions I found myself writing the following two lines over and over again when validating my API requests:

 createInsertSchema(todos)
   .omit('id', 'createdAt', 'updatedAt')
   .onUndeclaredKey('delete')


So I wanted to abstract this away into a function that currently looks like this:

export function insertSchema<
  T extends AnyPgTable & {
    id: AnyPgColumn
    createdAt: AnyPgColumn
    updatedAt: AnyPgColumn
  },
>(table: T) {
  return createInsertSchema(table)
    .omit('id', 'createdAt', 'updatedAt')
    .onUndeclaredKey('delete')
}


The issue I am facing now is that I get a Property 'omit' does not exist on type ... error.
Initially I just used AnyPgTable as the generic type so I thought that adding the column definitions might help but I was seemingly wrong.
I don't know if this is the right place to ask but I would greatly appreciate any help :)
Was this page helpful?