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
Hi,
I have a procedure (technically, it's called procedure builder as an internal type) that is updating context. I want to reuse object of this context in an external function, but I have hard time extracting it.
E.g.:
import{initTRPC,TRPCError}from"@trpc/server";typeUnauthorizedContext={req: NextApiRequest;res: NextApiResponse;};const{ router, procedure, middleware }=initTRPC.context<UnauthorizedContext>().create();constauthProcedure=t.procedure.use(t.middleware(async({ ctx, next })=>{constauthObject=getAuthObject(ctx.req);if(!authObject){thrownewTRPCError({code: "UNAUTHORIZED",message: "Not authorized",});}returnnext({ctx: { ...ctx,auth: authObject,},});}),);typeAuth={// this is type I want to infer}constgetDataByAuth=(auth: Auth)=>{// do stuff}constprocedure=authProcedure.mutation(async({ ctx })=>{constdata=getDataByAuth(ctx.auth);returndata;});exportconstappRouter=t.router({ procedure });
Currently I infer type like that:
typeProcedureParams<PextendsProcedureBuilder<any>>=PextendsProcedureBuilder<infer X> ? X : never;typeProcedureContext<PextendsProcedureBuilder<any>>=ProcedureParams<P>["_ctx_out"];typeAuth=ProcedureContext<typeofauthProcedure>
I believe this might be extract as a helper.
Describe the solution you'd like to see
typeProcedureParams<PextendsProcedureBuilder<any>>=PextendsProcedureBuilder<infer X> ? X : never;exporttypeinferProcedureContext<PextendsProcedureBuilder<any>>=ProcedureParams<P>["_ctx_out"];// This might be useful to someone as well though I don't have a use caseexporttypeinferProcedureMeta<PextendsProcedureBuilder<any>>=ProcedureParams<P>["_meta"];
Describe alternate solutions
Bring your own type inferrers
Additional information
No response
👨👧👦 Contributing
🙋♂️ Yes, I'd be down to file a PR implementing this feature!
Funding
You can sponsor this specific effort via a Polar.sh pledge below
We receive the pledge once the issue is completed & verified
The text was updated successfully, but these errors were encountered:
Describe the feature you'd like to request
Hi,
I have a procedure (technically, it's called procedure builder as an internal type) that is updating context. I want to reuse object of this context in an external function, but I have hard time extracting it.
E.g.:
Currently I infer type like that:
I believe this might be extract as a helper.
Describe the solution you'd like to see
Describe alternate solutions
Bring your own type inferrers
Additional information
No response
👨👧👦 Contributing
Funding
The text was updated successfully, but these errors were encountered: