HonoH
Hono16mo ago
ForkMeDaddy

Client Response

I have a problem where what my API returns is not what the TS types say it is:

For example what I actually receive when logging res is simply an object that looks like this {email, message}. But there is no ok, json() that my IDE says there should be.

This is the route:

const ResponeSchema = z.object({
  message: z.string(),
  email: z.string().email(),
});
export const secret = new OpenAPIHono<{
  Variables: ContextVariables;
}>().openapi(
  createRoute({
    method: "get",
    path: "/api/secret",
    tags: ["Secret"],
    summary: "Shhh...",
    responses: {
      200: {
        description: "Success",
        content: {
          "application/json": {
            schema: ResponeSchema,
          },
        },
      },
    },
  }),
  (c) => {
    const user = c.get("user")!;
    return c.json(
      {
        message: "Secret Message",
        email: user.email,
      },
      200
    );
  }
);
image.png
Was this page helpful?