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

OpenAPI router unsafe assignment with fromHono #183

Open
kylecarhart opened this issue Oct 31, 2024 · 6 comments
Open

OpenAPI router unsafe assignment with fromHono #183

kylecarhart opened this issue Oct 31, 2024 · 6 comments

Comments

@kylecarhart
Copy link

kylecarhart commented Oct 31, 2024

I am getting a typescript error when trying to use fromHono().

Unsafe assignment of an `any` value.eslint[@typescript-eslint/no-unsafe-assignment](https://typescript-eslint.io/rules/no-unsafe-assignment)

I took a look at the types and saw this:

// src/adapters/hono.ts
export function fromHono<M>(
  router: M,
  options?: RouterOptions
): M & OpenAPIRouterType<M> & any {
  const openapiRouter = new HonoOpenAPIHandler(router, options)

  return new Proxy(router, {
    // ...
  }
}

Whats the reasoning for the any at the end of the return type? Same thing for fromIttyRouter as well... I'd have to disable a bunch of eslint rules for this file to get it working, but then I am losing all my type safety that I had before v2.

@alexanderatallah
Copy link

Seeing this as well - seems like a bug?

@louisgv
Copy link

louisgv commented Nov 1, 2024

It's been an issue since 2.0.0:

image

The older package's typing (itty-router-openapi) seems a bit more strict :-?

@G4brym
Copy link
Member

G4brym commented Nov 2, 2024

Hey there, I've just published a new release (v2.1.0) that removes the any from the adapters, can you confirm the issue is fixed?

@louisgv
Copy link

louisgv commented Nov 3, 2024

@G4brym - it seems the middleware registration typing is still wrong, I can't register middleware:
image

@louisgv
Copy link

louisgv commented Nov 3, 2024

The typing when grabbing the API for hono test is wrong with the testClient helper:
image

image

@kylecarhart
Copy link
Author

Honestly, I just went ahead and migrated away from itty-router and went straight to Hono with Zod OpenAPI Hono. Was able to reuse a lot of our existing code, just had to change the class based routes to the Hono way; no longer depending on Chanfana.

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

4 participants