HonoH
Hono11mo ago
meow

No Types for RPC with abstracted routes

I'm not getting any type hints from my Hono RPC client. I know there are warnings not to use the factory method, but as far as I knew this was the only way to have abstracted routes, which I find pretty important for organizing many routes.

type Env = {
  Variables: {
    db: typeof db
    mqtt: typeof mqtt
    redis: typeof redis
  }
}

function initApp(app: Hono<Env, BlankSchema, "/">) {
  app.use(async (ctx, next) => {
    ctx.set("db", db)
    ctx.set("mqtt", mqtt)
    ctx.set("redis", redis)
    await next()
  })
}

const factory = createFactory<Env>({ initApp })
export default factory
// ———————————————————————————————————————————
const app = factory.createApp()
  .route("/", root)
  .route("/config", config)
  .route("/redis", redis)

export type App = typeof app
// ———————————————————————————————————————————
const client = hc<App>(`http://${HOSTNAME}:${PORT}`)
export default client
Was this page helpful?