You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the example from the trpc server middleware for hono docs, in the createContext example the env is typed as Context<any, any, {}> is there a way to get the type safe bindings same as when using the hono routes directly so that var1 in the example below is typesafe?
import{trpcServer}from"@hono/trpc-server";import{initTRPC}from"@trpc/server";import{Hono}from"hono";import{z}from"zod";typeBindings={DB: D1Database;};typeHonoContext={env: Bindings;};constt=initTRPC.context<HonoContext>().create();constpublicProcedure=t.procedure;constrouter=t.router;constapp=newHono<{Bindings: Bindings}>();exportconstappRouter=router({usersCount: publicProcedure.query(async({ input, ctx })=>{constresult=awaitctx.env.DB.prepare("SELECT count(*) from user;").all();returnresult?.results[0]?.count;}),});app.use("/trpc/*",trpcServer({router: appRouter,createContext: (_opts,c)=>({// c is the hono contextvar1: c.env.DB,// This is not typesafevar2: c.req.header("X-VAR2"),}),}),);exporttypeAppRouter=typeofappRouter;
The text was updated successfully, but these errors were encountered:
May be related but I'm seeing similar issue with @hono/zod-validator where the bindings defined on the app is not present in the hook callback's context parameter passed to the zValidator() function.
Using the example from the trpc server middleware for hono docs, in the createContext example the env is typed as
Context<any, any, {}>
is there a way to get the type safe bindings same as when using the hono routes directly so that var1 in the example below is typesafe?The text was updated successfully, but these errors were encountered: