Skip to content

BUG: RPC types broken when using arrow function with a Promise #4765

@valerii15298

Description

@valerii15298

What version of Hono are you using?

4.12.2

Reproduction

import { Hono } from "hono";
import { hc } from "hono/client";

const app = new Hono().get("/", (c) =>
  Promise.resolve({ hello: "world" }).then((d) => c.json(d)),
);

const api = hc<typeof app>("");

// data has unknown type
const data = await api.index.$get().then((r) => r.json());

But the same code without arrow funcion works:

import { Hono } from "hono";
import { hc } from "hono/client";

const app = new Hono().get("/", (c) => {
  const resp = Promise.resolve({ hello: "world" }).then((d) => c.json(d));
  return resp;
});

const api = hc<typeof app>("");

// data has { hello: string; } type
const data = await api.index.$get().then((r) => r.json());

What is the expected behavior?

Types should be inferred in both cases

What do you see instead?

RPC json response has unknown type

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions