Strange trpc types with latest create-t3-app example app

Hello, I just installed a fresh create-t3-app with prisma, tailwind, and trpc. If we navigate to the example getAll query in server/api/routers/example.ts, and modify it as such:
getAll: publicProcedure.query(async ({ ctx }) => {
const values = await ctx.prisma.example.findMany();
return values;
}),
getAll: publicProcedure.query(async ({ ctx }) => {
const values = await ctx.prisma.example.findMany();
return values;
}),
The issue is that the TS type if we hover the mouse over values is strange:
const values: Prisma.PrismaPromise<(GetResult<{
id: string;
createdAt: Date;
updatedAt: Date;
}, unknown> & {})[]>
const values: Prisma.PrismaPromise<(GetResult<{
id: string;
createdAt: Date;
updatedAt: Date;
}, unknown> & {})[]>
In the past it would have looked like:
const values: Example[]
const values: Example[]
Has anyone else noticed this behavior in their project? Is this expected behavior? I noticed this in my personal project when I updated to the latest prisma packages. So I created a fresh create-t3-app to see if it was happening there as well, and was able to verify it was. It seems to potentially be related to prisma 4.16.x versions.
9 Replies
xenostar
xenostar12mo ago
Seems like potentially Prisma 4.16.X+ is having this issue.
JulieCezar
JulieCezar12mo ago
This part is written incorrectly.
getAll: publicProcedure.query(({ ctx }) => {
const values = ctx.prisma.example.findMany();
return ctx.prisma.example.findMany();
}),
getAll: publicProcedure.query(({ ctx }) => {
const values = ctx.prisma.example.findMany();
return ctx.prisma.example.findMany();
}),
1st why are you declaring values if you return a query again? You are douing double queries. 2nd you aren't awaiting queries which are async Better example
getAll: publicProcedure.query(({ ctx }) => {
const values = await ctx.prisma.example.findMany();

return values
}),
getAll: publicProcedure.query(({ ctx }) => {
const values = await ctx.prisma.example.findMany();

return values
}),
xenostar
xenostar12mo ago
Thanks! I totally get that this is not fully correct. My focus though is on the type of values, which seems to be incorrect. I refactored the code and you can see I am still getting this when hovering my house over values. What I would expect to see is Example[].
JulieCezar
JulieCezar12mo ago
I see now... I tried it myseld and get the same result However, when calling it it's return as normal
JulieCezar
JulieCezar12mo ago
JulieCezar
JulieCezar12mo ago
^ I returned only 1 object So yea... idk why it's shown like that but it works as expected 👍
JulieCezar
JulieCezar12mo ago
GitHub
FindMany returns wrong type after extending prisma client · Issue #...
Bug description Types inference breaks when you pass query as any to the findMany function in extended prisma client; const result = prisma.model.findMany(query as any); const id = result[0].id; /*...
JulieCezar
JulieCezar12mo ago
This is a known bug... hopefully will be fixed soon
xenostar
xenostar12mo ago
Thank you Julie!!