Nicolas
Nicolas16mo ago

Basic Inference not Working

I have been struggling to get basic type inferencing to work with trpc, react, and Drizzle ORM. This is what my server-side router is returning from the list method:
export const organizationRouter = router({
list: adminProcedure.query(async () => {
const response = await listOrganizations.all();
return response;
}),
export const organizationRouter = router({
list: adminProcedure.query(async () => {
const response = await listOrganizations.all();
return response;
}),
Where, if I hover over the response in the return, it says the type is:
const response: {
id: number;
name: string;
description: string | null;
}[]
const response: {
id: number;
name: string;
description: string | null;
}[]
However, on my client side, it says the type is any for the following:
const organizationData = trpc.organization.list.useQuery();
organizationData.data <---- ANY
const organizationData = trpc.organization.list.useQuery();
organizationData.data <---- ANY
Why is this basic type inferencing not happening? I am using Drizzle ORM to infer the return type on the router response; could this have something to do with it? Does trpc not work well with ORM's that use inference?
2 Replies
Nicolas
NicolasOP16mo ago
It works if I do the following:
list: adminProcedure.query(async () => {
const response = await listOrganizations.all();
return response as Organization[];
}),
list: adminProcedure.query(async () => {
const response = await listOrganizations.all();
return response as Organization[];
}),
But shouldn't trpc be able to inference it fine without having to force the output type? Seems like it defeats the point of trpc if I have to do that...
Parsa
Parsa2w ago
Did you ever manage to find a solution to this?

Did you find this page helpful?