Typing a helper function parameter to be a table with required column(s)

I'm having a hard time typing some helper functions where I need some params to accept any table as long as it implements certain required columns (key and type). Here's what i'm aiming for:
export function withTranslation<T extends AnyTable, TT extends AnyTable</* How to type this to enforce certain columns, e.g. "locale"? */>>(
  event: RequestEvent | ServerLoadEvent,
  table: T,
  translationsTable: TT,
  join: { field: ValueOf<T['_']['columns']>; reference: ValueOf<TT['_']['columns']> }
) {
  return dbpool.$with('tt').as((db) =>
    db
      .select({
        ...getTableColumns(table),
        ...getTableColumns(translationsTable),
      })
      .from(table)
      .leftJoin(
        translationsTable,
        and(
          eq(translationsTable.locale, event.locals.locale),
                            // ^^^^^^Property "locale" does not exist on type TT
          eq(join.field, join.reference))
        )
    );
}

Anyone have experience with this?
Was this page helpful?