HonoH
Hono11mo ago
lambert

RPC typing is behaving weird

I'm not sure if this might be an issue with my setup or with Hono itself, but I'm a bit at a loss here

I have a Hono router for projects which I want to use as a projectsClient with hc.
For this I take my projects Router and extract the Type like this:

type ProjectsRouter = typeof projectRoutes;
// The resulting type is:
type ProjectsRouter = Hono<BlankEnv, {
    "/": {
        $get: {
            input: {};
            output: {
                projects: {
                    name: string;
                    id: string;
                    image: string | null;
                    url: string | null;
                    slug: string;
                    description: string | null;
                }[];
            };
            outputFormat: "json";
            status: 200;
        };
    };
} & {
    ...;
}, "/">


Now I import ProjectsRouter in my frontend and my "/" output changes to [x: string]: any;

type ProjectsRouter = Hono<BlankEnv, {
    "/": {
        $get: {
            input: {};
            output: {
                [x: string]: any;
            };
            outputFormat: "json";
            status: 200;
        };
    };
} & {
    "/": {
        $post: {
            input: {
                json: {
                    name: string;
                    slug: string;
                    image?: string | undefined;
                    url?: string | undefined;
                    description?: string | undefined;
                };
            };
            output: {
                ...;
            };
            outputFormat: "json";
            status: ContentfulStatusCode;
        };
    };
}, "/">


I thought it might by my Typescript version or any other version but they work fine. Any other type exported from my backend to frontend works too. Anyone might have an idea here?

Thanks in advance!
Was this page helpful?