subbed
subbed2mo ago

Deno error on Hono Swagger UI

Hello. I am receiving a Deno error on the following snippet:
import { randomInt } from "node:crypto";
import { type Context, Hono } from "hono";
import { logger } from "hono/logger";
import { swaggerUI } from "@hono/swagger-ui";

const rootHandler = (ctx: Context): Response => {
return ctx.json({
r256: randomInt(0, 256),
});
};

const subHandler = (ctx: Context): Response => {
return ctx.json({
sub: ctx.req.param("sub"),
r256: randomInt(0, 256),
});
};

const app = new Hono();

app.use(logger());
app.get("/ui", swaggerUI({ url: "/doc" }));

app.get("/", rootHandler);
app.get("/:sub", subHandler);

Deno.serve({ port: 3000 }, app.fetch);
import { randomInt } from "node:crypto";
import { type Context, Hono } from "hono";
import { logger } from "hono/logger";
import { swaggerUI } from "@hono/swagger-ui";

const rootHandler = (ctx: Context): Response => {
return ctx.json({
r256: randomInt(0, 256),
});
};

const subHandler = (ctx: Context): Response => {
return ctx.json({
sub: ctx.req.param("sub"),
r256: randomInt(0, 256),
});
};

const app = new Hono();

app.use(logger());
app.get("/ui", swaggerUI({ url: "/doc" }));

app.get("/", rootHandler);
app.get("/:sub", subHandler);

Deno.serve({ port: 3000 }, app.fetch);
The problematic line is apparently this one: app.get("/ui", swaggerUI({ url: "/doc" }));. The error presented during deno check is:
error: TS2769 [ERROR]: No overload matches this call.
The last overload gave the following error.
Argument of type 'MiddlewareHandler<Env>' is not assignable to parameter of type 'H<BlankEnv, "/ui", BlankInput, HandlerResponse<any>>'.
Type 'MiddlewareHandler<Env>' is not assignable to type 'MiddlewareHandler<BlankEnv, "/ui", BlankInput>'.
Types of parameters 'c' and 'c' are incompatible.
Type 'Context<BlankEnv, "/ui", BlankInput>' is not assignable to type 'Context<Env, string, {}>'.
Property '#private' in type 'Context' refers to a different member that cannot be accessed from within type 'Context'.
app.get("/ui", swaggerUI({ url: "/doc" }));
~~~~~~~~~~~~~~~~~~~~~~~~~~
at file:///home/.../dev/core/hono/src/main.ts:22:16

TS2771 [ERROR]: The last overload is declared here.
at https://jsr.io/@hono/hono/4.6.4/src/types.ts:657:60
error: TS2769 [ERROR]: No overload matches this call.
The last overload gave the following error.
Argument of type 'MiddlewareHandler<Env>' is not assignable to parameter of type 'H<BlankEnv, "/ui", BlankInput, HandlerResponse<any>>'.
Type 'MiddlewareHandler<Env>' is not assignable to type 'MiddlewareHandler<BlankEnv, "/ui", BlankInput>'.
Types of parameters 'c' and 'c' are incompatible.
Type 'Context<BlankEnv, "/ui", BlankInput>' is not assignable to type 'Context<Env, string, {}>'.
Property '#private' in type 'Context' refers to a different member that cannot be accessed from within type 'Context'.
app.get("/ui", swaggerUI({ url: "/doc" }));
~~~~~~~~~~~~~~~~~~~~~~~~~~
at file:///home/.../dev/core/hono/src/main.ts:22:16

TS2771 [ERROR]: The last overload is declared here.
at https://jsr.io/@hono/hono/4.6.4/src/types.ts:657:60
This is the imports field in my deno.json:
"imports": {
"@hono/swagger-ui": "npm:@hono/swagger-ui@0.5.0",
"hono": "jsr:@hono/hono@4.6.4"
}
"imports": {
"@hono/swagger-ui": "npm:@hono/swagger-ui@0.5.0",
"hono": "jsr:@hono/hono@4.6.4"
}
The Swagger UI example is taken directly from Hono's docs.
1 Reply
subbed
subbedOP2mo ago
Any sort of help would be appreciated It seems like hono/swagger-ui@0.4.1 is successfully built, therefore this is a Hono issue, not a Deno issue

Did you find this page helpful?