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

typescript error with hono-openapi when upgrade hono to 4.6.17 #3884

Open
lesliechueng1996 opened this issue Feb 2, 2025 · 3 comments
Open
Labels

Comments

@lesliechueng1996
Copy link

What version of Hono are you using?

4.6.17

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

Bun workspace

What steps can reproduce the bug?

I am writing one api with hono, and openapi doc with hono-openapi.

The api like:

import { describeRoute } from 'hono-openapi';

export const validateOpenapiRoute = describeRoute({
  tags: ['api-tools'],
  description: 'Validate the openapi schema',
  responses: {
    200: {
      description: 'Successful validate the openapi schema',
      content: {
        'application/json': {
          schema: resolver(successEmptyResponseSchema),
        },
      },
    },
  },
});

apiTool.post('/validate-openapi-schema', validateOpenapiRoute, validateOpenapiValidator, async (c) => {
    const { openapiSchema } = c.req.valid('json');
 ...
});

When I use hono v4.6.16 and hono-openapi v0.4.4, everything works well.
But after I upgrade the hono to v4.6.17 ~ v4.6.20(latest), there are a lot of type error occured in the apiTool.post method.

when I hover the "validateOpenapiRoute" the error message is: 

没有与此调用匹配的重载。
  最后一个重载给出了以下错误。
    类型“MiddlewareHandler”的参数不能赋给类型“H<BlankEnv, "/validate-openapi-schema", BlankInput, HandlerResponse<any>>”的参数。
      不能将类型“MiddlewareHandler”分配给类型“MiddlewareHandler<BlankEnv, "/validate-openapi-schema", BlankInput>”。
        参数“c”和“c” 的类型不兼容。
          类型 "Context<BlankEnv, "/validate-openapi-schema", BlankInput>" 中缺少属性 "#private",但类型 "Context<any, string, {}>" 中需要该属性。ts(2769)
context.d.ts(184, 5): 在此处声明了 "#private"。
types.d.ts(389, 5): 在此处声明最后一个重载。


when I hover the "json" in "c.req.valid('json');" the error message is: 
类型“"json"”的参数不能赋给类型“never”的参数。ts(2345)
Image

What is the expected behavior?

No type error.

What do you see instead?

No response

Additional information

When I downgrade hono to 4.6.16, it works well.

@yusukebe
Copy link
Member

yusukebe commented Feb 3, 2025

Hi @lesliechueng1996

hono-openapi is not a Hono official project. cc: @MathurAditya724

@palmithor
Copy link

@yusukebe actually, hono/cors, which is an official hono project, has the same error

@yusukebe
Copy link
Member

yusukebe commented Feb 4, 2025

@palmithor How can I reproduce it?

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

No branches or pull requests

3 participants