larryx01L
tRPC3mo 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> {}


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;
});




In a trpc client i have

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


when i hover .testManualInterface i get output: {first_name: string}
when i hover .testInferredInterface i get 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.


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
Was this page helpful?