larryx01
larryx013w ago

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 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.
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
No description
No description
1 Reply
larryx01
larryx01OP3w ago
Essentially I want the TRPC proc to return output: TestManualInterface not output: {first_name: string}

Did you find this page helpful?