Skip to content

Type inference drops routes declared before use() when using method chaining #4388

@resYuto

Description

@resYuto

What version of Hono are you using?

4.6.5 4.9.5 (letest at this moment. sorry!)

What runtime/platform is your app running on? (with version if possible)

Cloudflare Workers (issue observed in local type inference only)

What steps can reproduce the bug?

When defining endpoints with method chaining, if a "use()" method is inserted, the routes declared before that "use()" are not included in the inferred type information.

import { Hono } from "hono";

const routerA = new Hono()
  .get("/", (c) => c.text("Hello from Router A!"))
  .use("/:slug", async (c, next) => {
    return next();
  })
  .post("/:slug", (c) => c.text("Hello from Router A with slug!"));

const app = new Hono().route("/a", routerA);

export type AppType = typeof app;
export default app;

What is the expected behavior?

Chained routes defined before "use()" should still be inferred in the types.

What do you see instead?

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions