lanc3
lanc3
Explore posts from servers
DTDrizzle Team
Created by lanc3 on 1/8/2024 in #help
Parsing error reading .JSX files
No description
1 replies
TTCTheo's Typesafe Cult
Created by lanc3 on 6/19/2023 in #questions
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.
3 replies