Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path is not inferred when chaining after use #3001

Closed
jordanbtucker opened this issue Jun 20, 2024 · 0 comments · Fixed by #3087
Closed

path is not inferred when chaining after use #3001

jordanbtucker opened this issue Jun 20, 2024 · 0 comments · Fixed by #3087
Labels

Comments

@jordanbtucker
Copy link

What version of Hono are you using?

4.4.7

What runtime/platform is your app running on?

Node.js

What steps can reproduce the bug?

When chaining after use and not providing a path to get.

new Hono()
  .use("/:id", async (c, next) => {
    await next();
  })
  .get((c) => {
    const id = c.req.param("id");
    return c.text(id); // TypeScript complains that `id` might be `undefined`.
  });

When providing a path to get.

new Hono()
  .use("/:id", async (c, next) => {
    await next();
  })
  .get("/:id", (c) => {
    const id = c.req.param("id");
    return c.text(id); // TypeScript is happy.
  });

Compare this to chaining after post and not providing a path to get.

new Hono()
  .post("/:id", async (c) => {
    const id = c.req.param("id");
    return c.text(id);
  })
  .get((c) => {
    const id = c.req.param("id");
    return c.text(id); // TypeScript is happy.
  });

What is the expected behavior?

That path for chained app.HTTP_METHOD calls should be inferred after a app.use call.

What do you see instead?

That path for chained app.HTTP_METHOD calls is not being inferred after a app.use call.

Additional information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant