natef
natef
TtRPC
Created by natef on 9/25/2023 in #❓-help
TypeScript Issue: router.createCaller Implicitly has Return Type "any"
Hello everyone, I'm currently working on a project using tRPC and Prisma. However, I've run into an issue with TypeScript when I return the return value of a mutation within another mutation of the same router. Here's the relevant code snippet: import { UpdateProfile } from "@acme/validation/user"; import { type CallerContext } from "."; import { createTRPCRouter, protectedProcedure } from "../common/trpc"; export const userRouter = createTRPCRouter({ // ... (Other procedures) update: protectedProcedure .input(UpdateProfile) .mutation(async ({ ctx, input }) => { const user = await ctx.prisma.user.update({ where: { id: ctx.auth.userId }, data: input, }); return userCaller(ctx).someOtherAction(); }), someOtherAction: protectedProcedure.mutation(async ({ ctx }) => { const user = await ctx.prisma.user.findUnique({ where: { id: ctx.auth.userId }, }); return user; }), }); export const userCaller = (ctx: CallerContext) => userRouter.createCaller(ctx); TypeScript is complaining about this line: export const userCaller = (ctx: CallerContext) => userRouter.createCaller(ctx); The error message is: 'userCaller' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. Has anyone faced this issue before, and if so, how can it be resolved? Any guidance would be greatly appreciated!
2 replies