HonoH
Hono2y ago
Phil @

[zod, bun]#openapi async/await doesn't work

This ossue was previously on https://discord.com/channels/1011308539819597844/1012485912409690122/1242558525012709539, but I was advised to open it here.

here is a noob question. Im quite new to TS, bun and Hono with Zod. I cant make sense of why TS is screaming at me in the first line with async
apps.openapi(routeGetApp, async (c) => {
                          ~~~~~~~~~~~~~~
  try {
    const { identifier } = c.req.valid('param');
    const result = await db.query.app.findFirst({
      where: eq(app.name, identifier),
      with: { feature: true },
    });
    if (!result) return c.notFound();
    console.log(result);
    return c.json({
      id: result.id,
      identifier: result.name,
      features: {
        featureX: result.feature.deleteMessage,
        featureY: result.feature.inviteLinks,
      },
    });
  } catch (error) { return c.json(error, 500); }
});


the error reads
Argument of type '(c: Context<Env, "/:identifier", { in: { param: { identifier?: string; }; }; out: { param: { identifier?: string; }; }; }>) => Promise<Response>' is not assignable to parameter of type 'Handler<Env, "/:identifier", { in: { param: { identifier?: string; }; }; out: { param: { identifier?: string; }; }; }, HandlerTypedResponse<{ id?: number; identifier?: string; features?: { featureX?: boolean; featureY?: number; }; }>>'.
  Type 'Promise<Response>' is not assignable to type 'HandlerTypedResponse<{ id?: number; identifier?: string; features?: { featureX?: boolean; featureY?: number; }; }>'.
    Type 'Promise<Response>' is not assignable to type 'Promise<TypedResponse<{ id?: number; identifier?: string; features?: { featureX?: boolean; featureY?: number; }; }>>'.
      Type 'Response' is missing the following properties from type 'TypedResponse<{ id?: number; identifier?: string; features?: { featureX?: boolean; featureY?: number; }; }>': data, formatts(2345)


I think im returning my result wrong? it works fine, when returning it normally without my DB stuff and async/await
I havent tried running it with that error.. but I kind of want to resolve it first regardless.
Was this page helpful?