Consumer tRPC client package from private API type?

I have a monrepo (template from t3-turbo), with a tRPC API package. I'd like to expose a router for a public SDK by simply exposing the type of that router such that a tRPC client can be created, like
// private api package
export const publicRouter = createTRPCRouter({
user: publicUserRouter,
more...
});

// public client package
const Client = (token: string) =>
createTRPCProxyClient<PublicRouter>({
links: [
loggerLink({
enabled: (opts) =>
process.env.NODE_ENV === "development" ||
(opts.direction === "down" && opts.result instanceof Error),
}),
httpBatchLink({
url: `${getBaseUrl()}/api/trpc/public`,
headers: {
Authorization: `Bearer ${token}`,
},
}),
],
transformer: superjson,
});
// private api package
export const publicRouter = createTRPCRouter({
user: publicUserRouter,
more...
});

// public client package
const Client = (token: string) =>
createTRPCProxyClient<PublicRouter>({
links: [
loggerLink({
enabled: (opts) =>
process.env.NODE_ENV === "development" ||
(opts.direction === "down" && opts.result instanceof Error),
}),
httpBatchLink({
url: `${getBaseUrl()}/api/trpc/public`,
headers: {
Authorization: `Bearer ${token}`,
},
}),
],
transformer: superjson,
});
The issue is that I cannot get Typescript to incorporate type dependencies i.e. from prisma into this package. I'd like to just compile each required type into index.d.ts, but this doesn't seem to be something typescript supports. Has anyone else encountered this issue? Thinking about just using something like Zodios but it seems redundant to write these types knowing they exist already.
2 Replies
Scot
Scot2y ago
So you’re trying to expose a trpc api publically?
lanc3
lanc32y ago
Sorta, just the types of the routers. I don't want to expose the implementation for obvious reasons, but I want an api client
Want results from more Discord servers?
Add your server