KIPRI 🚀
KIPRI 🚀
DTDrizzle Team
Created by KIPRI 🚀 on 8/19/2023 in #help
Correct typing when using "columns" as param
Hello awesome people at Drizzle, I'm having this problem and I don't know how to fix it. So... I have this RoleManager service that has a method called getByName that can take in columns. The problem is that I can't seem to type this query in a nice way and what I've done doesn't tickle me the right way. xD
static async getByName<TColumns extends keyof RoleModel>(
roleName: RoleModel["name"],
columns?: Partial<Record<TColumns, boolean>>,
): Promise<Pick<RoleModel, TColumns> | undefined> {
const role = await db.query.roles
.findFirst({ where: eq(roles.name, roleName), columns });

return role as unknown as Pick<RoleModel, TColumns> | undefined;
}
static async getByName<TColumns extends keyof RoleModel>(
roleName: RoleModel["name"],
columns?: Partial<Record<TColumns, boolean>>,
): Promise<Pick<RoleModel, TColumns> | undefined> {
const role = await db.query.roles
.findFirst({ where: eq(roles.name, roleName), columns });

return role as unknown as Pick<RoleModel, TColumns> | undefined;
}
5 replies