Response loses type when specifying type arguments manually

Hi there! Just started messing around with Hono and was trying to optimize for typesafety. The docs state that adding the path as a generic parameter can help with type inferencing https://hono.dev/docs/guides/rpc#specify-type-arguments-manually so I gave this a shot
export const WORKSPACE_ROUTE = "/workspace";

// NOTE: added a string generic param
const app = new Hono().get<"/:id/features">("/:id/features", (c) => {
return c.json({ response: c.req.param("id") });
});

export default app;

const client = hc<typeof app>(WORKSPACE_ROUTE);

export type Client = typeof client;

export const workspaceClient = (...args: Parameters<typeof hc>): Client => hc<typeof app>(...args);

const response = await workspaceClient("/")[":id"].features.$get({ param: { id: "123" } });
export const WORKSPACE_ROUTE = "/workspace";

// NOTE: added a string generic param
const app = new Hono().get<"/:id/features">("/:id/features", (c) => {
return c.json({ response: c.req.param("id") });
});

export default app;

const client = hc<typeof app>(WORKSPACE_ROUTE);

export type Client = typeof client;

export const workspaceClient = (...args: Parameters<typeof hc>): Client => hc<typeof app>(...args);

const response = await workspaceClient("/")[":id"].features.$get({ param: { id: "123" } });
But my response type from response is: ClientResponse<{}, StatusCode, string> However if I remove the generic parameter (i.e. remove the <"/:id/features">, my response is accurately typed
ClientResponse<{
response: string;
}, StatusCode, "json">
ClientResponse<{
response: string;
}, StatusCode, "json">
I was wondering if I was missing something? Or maybe this is not necessary since I'm creating a typed client for re-use:
export type Client = typeof client;

export const workspaceClient = (...args: Parameters<typeof hc>): Client => hc<typeof app>(...args);
export type Client = typeof client;

export const workspaceClient = (...args: Parameters<typeof hc>): Client => hc<typeof app>(...args);
I tried searching around a bit but all the examples I saw in other GH issues or discussions didn't strongly type the path like this. Thanks for any help!
RPC - Hono
Web framework built on Web Standards for Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Node.js, and others. Fast, but not only fast.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server