HonoH
Hono•8mo ago
Mattèo

Got `unknown` type on res.json() on a OpenAPI RPC route

Hey ! I have an issue with RPC client and OpenAPI route inference.

Reproduction : https://stackblitz.com/edit/vitejs-vite-lqsp6pho?file=index.ts

import { hc } from "hono/client"
import app from "./openapi"
import { serve } from "@hono/node-server"

serve(app)

const client = hc<typeof app>("http://localhost:3000")

const res = await client["calendar-debug"].$get({
/*   ^? const res: ClientResponse<{
    page: number;
    limit: number;
    total: number;
    events: {
        type: string;
        title: string;
        status: string;
        clubId: string;
....

Type of res seems to be good
*/
  query: {
    page: "1",
    limit: "10",
    clubId: "1",
    sportId: "1",
  },
})
const data = await res.json() 
//    ^? unknown

console.log(data)


Does someone had this problem before, or can someone help me?

Wishing you a good day 😉
StackBlitzMattèo Gauthier
Next generation frontend tooling. It's fast!
Was this page helpful?