Infer Types from Partial Select Prepared Statement

Hi all, I am not sure if I am inferring the types of a partial select properly, below is what I am trying to do:
export const deploymentListByOrg = db
.select({ id: deployments.id, name: deployments.name, description: deployments.description })
.from(deployments)
.where(eq(deployments.organizationId, sql.placeholder("orgId")))
.prepare();
export type DeploymentListResponse = typeof deploymentListByOrg.all;
// export type DeploymentListResponse = { id: number; name: string; description: string | null }[]; <--- this is the type of the response that should be inferred
export const deploymentListByOrg = db
.select({ id: deployments.id, name: deployments.name, description: deployments.description })
.from(deployments)
.where(eq(deployments.organizationId, sql.placeholder("orgId")))
.prepare();
export type DeploymentListResponse = typeof deploymentListByOrg.all;
// export type DeploymentListResponse = { id: number; name: string; description: string | null }[]; <--- this is the type of the response that should be inferred
Is this the recommended way to do this? Is there a better way of inferring these types? I need to infer these types because when using this with tRPC, the frontend thinks the response is any unless I cast the return type with as This is what it's saying the types is, but I don't want to have the Promise<> just the actual data that is returned
No description
3 Replies
Angelelz
Angelelz13mo ago
Don't you have to await it? You could use the Awaited Generic type helper
Faris
Faris13mo ago
You can do export type DeploymentListResponse = Awaited<ReturnType<typeof deploymentListByOrg.execute>>;
Nicolas
Nicolas12mo ago
Thanks guys, didnt know that was a thing lol
Want results from more Discord servers?
Add your server