Nikola
Nikola
KKysely
Created by Nikola on 2/6/2024 in #help
Dynamic return type based on provided select array
So I have this function:
async getBillableUsers(select: SelectExpression<DB, 'user_data'>[]) {
return this.db
.selectFrom('user_data')
.select(select)
.where((eb) => eb.or([eb('billability_type', '=', 'Billable'), eb('billability_type', 'is', null)]))
.execute();
}
async getBillableUsers(select: SelectExpression<DB, 'user_data'>[]) {
return this.db
.selectFrom('user_data')
.select(select)
.where((eb) => eb.or([eb('billability_type', '=', 'Billable'), eb('billability_type', 'is', null)]))
.execute();
}
And when I call it I want the return type to contain only the fields that were provided in the select parameter.
const billableUsers = await this.getBillableUsers(['id', 'work_email']);
const billableUsers = await this.getBillableUsers(['id', 'work_email']);
In the result above, billableUsers contains all user_data column values, how can I narrow it down? I tried a lot of things but I keep getting type errors. I am using the kysely-codegen library for the types. Thanks for the help!
3 replies