chanfana icon indicating copy to clipboard operation
chanfana copied to clipboard

OpenAPI router unsafe assignment with `fromHono`

Open kylecarhart opened this issue 1 year ago • 6 comments

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.

kylecarhart avatar Oct 31 '24 20:10 kylecarhart

Seeing this as well - seems like a bug?

alexanderatallah avatar Nov 01 '24 02:11 alexanderatallah

It's been an issue since 2.0.0:

image

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

louisgv avatar Nov 01 '24 02:11 louisgv

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?

G4brym avatar Nov 02 '24 17:11 G4brym

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

louisgv avatar Nov 03 '24 20:11 louisgv

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

image

louisgv avatar Nov 03 '24 21:11 louisgv

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.

kylecarhart avatar Nov 08 '24 14:11 kylecarhart