Docs Issue: middleware Typescript errors
Docs listed here produce typescript errors - https://chanfana.pages.dev/advanced-topics-patterns#middleware-and-interceptors
No overload matches this call.
The last overload gave the following error.
Argument of type 'typeof ProtectedEndpoint' is not assignable to parameter of type 'H<{ Bindings: Env; }, "/protected", BlankInput, Promise<any>>'.ts(2769)
types.d.ts(774, 5): The last overload is declared here.
Any ideas?
I'm getting the same
@cendyne im doing it like this now
const openapi = fromHono(new Hono());
openapi.use(accountMiddleware);
openapi.use(adminMiddleware);
openapi.route("/group", groupRoutes);
export default openapi;
Thank you for responding! I do plan to use this method for some middleware, however some routes need to have route-specific middleware. For example, I regularly do something like this:
openapi.get("/object/:id", hasScope('object:*'), ObjectReadHandler)
openapi.put("/object/:id", hasScope('object:create'), ObjectCreateHandler)
openapi.delete("/object/:id", hasScope('object:delete'), ObjectDeleteHandler)
I've found this pattern to be very useful in hono at separating authorization from code.
For now, I'm using as any to bypass the typescript error. I look forward to its resolution.
openapi.get("/object/:id", hasScope('object:*'), ObjectReadHandler as any)
openapi.put("/object/:id", hasScope('object:create'), ObjectCreateHandler as any)
openapi.delete("/object/:id", hasScope('object:delete'), ObjectDeleteHandler as any)
May be we can try extending OpenAPIRoute for reusable logic but not very convenient and reusable with regular hono.