What version of Hono are you using?
4.11.2
What runtime/platform is your app running on? (with version if possible)
Bun 1.3.4
What steps can reproduce the bug?
import { Hono } from "hono";
import { hc } from "hono/client";
import { createMiddleware } from "hono/factory";
const middleware = createMiddleware(async (c) => {
if (Math.random() > 0.5) {
return;
} else {
return c.json({ cause: "Unauthorized" as const }, 401);
}
});
const app = new Hono().get("/", middleware, (c) => {
return c.json({ message: "Hello Hono!" });
});
export default app;
type AppType = typeof app;
const api = hc<AppType>("");
const response = await api.index.$get();
const json = await response.json(); // Should be `{ cause: "Unauthorized" } | { message: "Hello Hono!" }`
What is the expected behavior?
json should be typed as { cause: "Unauthorized" } | { message: "Hello Hono!" }, like in previous versions
What do you see instead?
json is typed as { message: "Hello Hono!" }
Additional information
#4598 seems to be the cause of the issue. It only occurs when the middleware returns a union type
What version of Hono are you using?
4.11.2
What runtime/platform is your app running on? (with version if possible)
Bun 1.3.4
What steps can reproduce the bug?
What is the expected behavior?
jsonshould be typed as{ cause: "Unauthorized" } | { message: "Hello Hono!" }, like in previous versionsWhat do you see instead?
jsonis typed as{ message: "Hello Hono!" }Additional information
#4598 seems to be the cause of the issue. It only occurs when the middleware returns a union type