HonoH
Hono6mo ago
dan—1106

Inferring the response type of a handler

I'm trying to infer the return type of a route on my server. Any tips on what I'm doing wrong?
import type { Env } from "@/types";
import { createFactory } from "hono/factory";
import { InferResponseType } from "hono";

const factory = createFactory<Env>();

export const helloWorld = factory.createHandlers(async (c) => {
  return c.json({
    message: "Hello World",
  });
});

type Route = typeof helloWorld[0]
type RouteResponse = Awaited<ReturnType<Route>>;
type Foo = InferResponseType<RouteResponse, 200>


The route response type is
type RouteResponse = void | Response | (Response & TypedResponse<{
    message: string;
}, ContentfulStatusCode, "json">)


Foo is
type Foo = never


any tips on what I'm doing wrong? I'm trying to get back something along the lines of {
message: string;
}
Was this page helpful?