tRPCttRPC
Powered by
larryx01L
tRPC•4mo ago•
2 replies
larryx01

TRPC type aliasing

I have these two interfaces set up. One manually defined with TS interface and one using the output of a Zod schema

export interface TestManualInterface {
  first_name: string;
}

export const testManualInterfaceSchema = z.object({
  first_name: z.string()
});

export interface TestInferredInterface extends z.output<typeof testManualInterfaceSchema> {}
export interface TestManualInterface {
  first_name: string;
}

export const testManualInterfaceSchema = z.object({
  first_name: z.string()
});

export interface TestInferredInterface extends z.output<typeof testManualInterfaceSchema> {}


i have these 2 procs set up - one returning the manual interface and the other returning the inferred interface

const testManualInterface = publicProcedure.query(async ({ input }) => {
  return {
    first_name: "Test Build 1"
  } as TestManualInterface;
});

const testInferredInterface = publicProcedure.query(async ({ input }) => {
  return {
    first_name: "Test Build 1"
  } as TestInferredInterface;
});
const testManualInterface = publicProcedure.query(async ({ input }) => {
  return {
    first_name: "Test Build 1"
  } as TestManualInterface;
});

const testInferredInterface = publicProcedure.query(async ({ input }) => {
  return {
    first_name: "Test Build 1"
  } as TestInferredInterface;
});




In a trpc client i have

  let testManualInterface = trpc.builds.testManualInterface.query();
  let testInferredInterface = trpc.builds.testInferredInterface.query();
  let testManualInterface = trpc.builds.testManualInterface.query();
  let testInferredInterface = trpc.builds.testInferredInterface.query();


when i hover
.testManualInterface
.testManualInterface
i get
output: {first_name: string}
output: {first_name: string}

when i hover
.testInferredInterface
.testInferredInterface
i get
output: TestInferredInterface
output: TestInferredInterface


why is this the case? why isnt the .testManualInterface using the alias as the output?

I am running into an issue where a TRPC proc is returnin a large interface, so i get TS compilation error
The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.
The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.


I am trying to fix this by having the function return the alias instead of the expanded
{....}
{....}
, but not sure why TRPC converts the non Zod-inferred interfaces into the expanded object type definition vs the alias

I want to avoid turning my large interface type into a Zod type just to avoid this error
Screenshot_2025-10-21_at_5.02.16_PM.png
Screenshot_2025-10-21_at_5.02.24_PM.png
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

tRPC query has any type
KrishnaKKrishna / ❓-help
3y ago
tRPC type error on turborepo
shuSshu / ❓-help
3y ago
Monorepo with shared trpc router type
MugetsuMMugetsu / ❓-help
8mo ago
TRPC type checking during build fails
EvanEEvan / ❓-help
3y ago