shadow
Question: Is there a way to have a base interface for Trpc router?
Hi, So I am trying to see if there is way to keep methods inside trpc routes consistent,
Like in case of classes you could define an interface with required functions. Is there a way to do this in Trpc router aswell?
Like ex:
interface A { function X(L: string){} }
class B implements A {} // error missing function X
Similarly I would like to know if its possible to do with trpc router routes aswell. As I have multiple routes with similar methods.
What i tried
interface MyMethods {
stateSubscribe: (
input: undefined,
opts: { onData: (state: string) => void },
) => void;
}
export const campaignRouter = createTRPCRouter<MyMethods>({
createCampaign: protectedProcedure.query(({ ctx }) => {
throw new TRPCError({
message: "Not implemented",
code: "NOT_IMPLEMENTED",
});
}),
stateSubscribe: protectedProcedure.query(({ ctx }) => {
throw new TRPCError({
message: "Not implemented",
code: "NOT_IMPLEMENTED",
});
}),
});
Any help would be wonderful.1 replies