tRPCttRPC
Powered by
natefN
tRPC•3y ago•
1 reply
natef

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);
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!
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

[Typescript] Client query / mutate has any type
KhojoKKhojo / ❓-help
10mo ago
[Typescript] Client query/mutate has any type
Mr. JokerMMr. Joker / ❓-help
12mo ago
Router type = any in monorepo...
beastieboardBbeastieboard / ❓-help
12mo ago