Table factory typescript problem

I have a basic table schema that all tables share (id, timestamps and more) and I'm trying to write an helper function that returns a pgTable with these fields already added. Right now it looks like this:
const baseTable: PgTableFn = (tableName, fields, extraConfig) => 
  pgTable(
    tableName, 
    {
      id: uuid("id").primaryKey(), 
      ...fields, 
      createdAt: timestamp("created_at"), 
      updatedAt: timestamp("updated_at")
    }, 
    extraConfig
  );

const testTable = baseTable(
  "test_table", 
  { test: text("test") }, 
  table => ({
    testIdx: index().on(table.test), // <- This is ok
    errIdx: index().on(table.createdAt) // <- This gives me an error
  })
);

This is wrong though because testTable is not typed correctly and it is missing all the shared fields. How would I go about correcting this?
Was this page helpful?