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

(zod-openapi) - middleware app.use() typing errors #187

Closed
callumfrance opened this issue Oct 4, 2023 · 3 comments
Closed

(zod-openapi) - middleware app.use() typing errors #187

callumfrance opened this issue Oct 4, 2023 · 3 comments

Comments

@callumfrance
Copy link
Contributor

callumfrance commented Oct 4, 2023

Following the README section of middleware - https://github.com/honojs/middleware/tree/main/packages/zod-openapi#middleware

My understanding is that Zod OpenAPI hono is simply an extension on top of the regular Hono, and so any Hono work should be compatible with OpenAPI Hono. As such I would expect the following to work using OpenAPIHono() (using the Hono JWT for example)-

import { OpenAPIHono, createRoute } from "@hono/zod-openapi";

const app = new OpenAPIHono();

app.use("/fizz", jwt({ secret: "a-secret" }));

app.get("/fizz", (c) => {
    const payload = c.get("jwtPayload");
    return c.json(payload);
});

However, TypeScript gives me a large type error on the app.use() line -

No overload matches this call.
  Overload 1 of 2, '(...handlers: MiddlewareHandler<Env, never, {}>[]): Hono<Env, {}, "/">', gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'MiddlewareHandler<Env, never, {}>'.
  Overload 2 of 2, '(path: "/fizz", ...handlers: MiddlewareHandler<Env, "/fizz", {}>[]): Hono<Env, {}, "/">', gave the following error.
    Argument of type 'MiddlewareHandler' is not assignable to parameter of type 'MiddlewareHandler<Env, "/fizz", {}>'.
      Types of parameters 'c' and 'c' are incompatible.
        Type 'Context<Env, "/fizz", {}>' is not assignable to type 'Context<any, string, {}>'.
          Types of property 'req' are incompatible.
            Type 'HonoRequest<"/fizz", unknown>' is not assignable to type 'HonoRequest<string, unknown>'.
              Types have separate declarations of a private property 'paramData'.ts(2769)

I am finding this error on any use of app.use(), not just for the JWT.

If it is relevant, I am using bun

@callumfrance callumfrance changed the title (zod-openapi) - middleware .use() typing errors (zod-openapi) - middleware app.use() typing errors Oct 4, 2023
@yusukebe
Copy link
Member

yusukebe commented Oct 5, 2023

Hi @callumfrance

Thank you for raising the issue. I'm going on a trip, so I'll look at it later.

@yusukebe
Copy link
Member

@callumfrance

Can we close this issue?

@callumfrance
Copy link
Contributor Author

Yep, this seems to no longer be an issue 👍

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

No branches or pull requests

2 participants