Memefella
Memefella3mo ago

v11: inferRouterInputs is returning `void | <zod object>` so it's unusable?

can't see what I'm doing different than docs would be really cool if this worked
updateAreaType: procedure
.input(z.object({ areaTypeId: z.string(), data: AreaType.partial() }).required())
.output(z.any())
.mutation(async ({ input, ctx }) => ctx.app.service.Area.updateAreaType(input, ctx)),
updateAreaType: procedure
.input(z.object({ areaTypeId: z.string(), data: AreaType.partial() }).required())
.output(z.any())
.mutation(async ({ input, ctx }) => ctx.app.service.Area.updateAreaType(input, ctx)),
import { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
import type { Router } from './area.router';

type RouterInput = inferRouterInputs<Router>;
type RouterOutput = inferRouterOutputs<Router>;
import { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
import type { Router } from './area.router';

type RouterInput = inferRouterInputs<Router>;
type RouterOutput = inferRouterOutputs<Router>;
async updateAreaType(input: RouterInput['updateAreaType'], ctx: Context): RouterOutput['updateAreaType'] {
console.log('Area.Service.updateAreaType', input.areaTypeId, input.data);
const updatedAreaType = await ctx.app.model.AreaType.findByIdAndUpdate(input.areaTypeId, input.data, { new: true })
.lean()
.exec();
if (!updatedAreaType) {
throw new Error('AreaType update failed');
}
return updatedAreaType as AreaType;
}
async updateAreaType(input: RouterInput['updateAreaType'], ctx: Context): RouterOutput['updateAreaType'] {
console.log('Area.Service.updateAreaType', input.areaTypeId, input.data);
const updatedAreaType = await ctx.app.model.AreaType.findByIdAndUpdate(input.areaTypeId, input.data, { new: true })
.lean()
.exec();
if (!updatedAreaType) {
throw new Error('AreaType update failed');
}
return updatedAreaType as AreaType;
}
No description
No description
1 Reply
Memefella
MemefellaOP3mo ago
adding if (!input) throw new Error('Input should not be void'); fixed it, but it shouldn't even get to the method if the data isn't sent, so that's a superfluous check. i don't think RouterInput should be returning void | doesn't seem like inferRouterOutputs uses the .output but instead uses the mutation return type.. so it's a circular reference. yet the inferRouterInputs is clearly using the .input ya inferTransformedProcedureOutput is referencing the return type, so I can't do a bi-directional reference, requiring me to abstract the zod schema, which is a pain. I hate jumping around code just to edit types