How can I get a type from SelectedFields<MySqlColumn, Table>?

Hi guys sorry to bother buy I'm trying to build a Repository Pattern with Drizzle and I stuck with a type.

The interface with I came up is
interface BaseRepository<T extends MySqlTable,
    S extends SelectedFields<MySqlColumn, T>> {
    findAll(): Promise<S[]>;
    findById(id: number): Promise<S | null>;
    create(data: InferInsertModel<T>): Promise<number>;
    delete(id: number): Promise<void>;
    findAllPaginated(page: number, limit: number, condition?: SQL<unknown>): Promise<Pagination<S>>;
}

export abstract class CrudRepository<
    M extends MySqlTable & { id: SQLWrapper, deletedAt: SQLWrapper },
    S extends SelectedFields<MySqlColumn, M>
> implements BaseRepository<M, S> {
 // ....implementation
}

export const userTable = mysqlTable("user", {
    id: int('id').primaryKey().autoincrement().notNull(),
    email: varchar("email", { length: 255 }).notNull(),
    password: varchar("password", { length: 255 }).notNull(),
    name: varchar("name", { length: 255 }).notNull(),
    deletedAt: timestamp("deleted_at"),
});

const userSelect = {
    id: userTable.id,
    email: userTable.email,
    name: userTable.name,
};

export class UserRepository extends CrudRepository<typeof userTable, typeof userSelect> {
    constructor(db: DbConnection) {
        super(userTable, db, userSelect);
    }
}

const userRepository = new UserRepository(db);

const allUsers = userRepository.findAll();


This is working fine but my problem is that the type of allUsers is

const allUsers: Promise<{
    id: MySqlColumn<...>;
    email: MySqlColumn<...>;
    name: MySqlColumn<...>;
}[]>

and I'm trying to get something like
const allUsers: Promise<{
    id: number;
    name: string;
    email: string;
}>


So i want to do something like InferSelectModel<S> but I can't and I'm not sure how to do it, any hint on how can i solve it o what documentation can i read to understand a bit more and solve it?
Thanks
Was this page helpful?