T
tRPC

NextJS and createProxySSGHelpers context type error

NextJS and createProxySSGHelpers context type error

Ooljimenez12/26/2022
Hi guys, do you guys know a better way of clean this typescript error? createProxySSGHelpers({ router: appRouter, ctx: await createContext({ //this cause type error because ctx.req and ctx.res from getServerSideProps or getStaticProps are diferent from NextApiRequest and NextApiResponse req: ctx.req, res: ctx.res, }), transformer: superjson, }); i ended doing this export const trpcServerContext = async (ctx: NextServerContext) => createProxySSGHelpers({ router: appRouter, ctx: await createContext({ req: ctx.req as NextApiRequest, res: ctx.res as NextApiResponse, }), transformer: superjson, }); but maybe exist a better way.
UUUnknown User1/15/2023
4 Messages Not Public
Sign In & Join Server To View
Jjulius1/15/2023
Typing your createContext accordingly i think should work
export async function createContext(
opts:
| {
req: CreateNextContextOptions['req'];
res: CreateNextContextOptions['res'];
}
| {
req: NextApiRequest;
res: NextApiResponse;
},
) {
// for API-response caching see https://trpc.io/docs/caching

return await createContextInner({});
}
export async function createContext(
opts:
| {
req: CreateNextContextOptions['req'];
res: CreateNextContextOptions['res'];
}
| {
req: NextApiRequest;
res: NextApiResponse;
},
) {
// for API-response caching see https://trpc.io/docs/caching

return await createContextInner({});
}

Looking for more? Join the community!

T
tRPC

NextJS and createProxySSGHelpers context type error

Join Server
Recommended Posts
Validating PermissionsHi! A common operation that I'm doing in tRPC is validating that a person has permissions to perforAny typescript chads able know if it's possible to map a type to another type w genericsNot 100% sure if this is appropriate to ask here but I figured there's a lot of good TS developers ouseQuery enabled not working???Even setting the `enabled` to false --> `trpc.order.get({id: "123"}, {enabled: false})` still make`QueryClientProvider` not included in `withTRPC`?Trying to use `import { useIsMutating } from "react-query"` but it's throwing `Error: No QueryClientHandle React error boundarySeems like Im doing something wrong as I can't handle the error boundary from trpc query. I've queryAny tips for Typescript slowness?We successfully migrated from 9.x to 10 but are still seeing slow VS Code perf (10+ seconds to get aChange status of useMutation from 'success' back to 'idle'Hiya, I have a mutation for creating stuff that can run a few different ways on a page, and I want tIs it possible to call one procedure in another?I have multiple routers in my trpc server. For example userRouter (e.g. procedure: getUser) and postHandling Query Errors at Root of App (v9)I want to show an error toast on my `NextJS` frontend every time there is an error from `useQuery` itRPC Client webpack errorAs soon as I add the client part to my legacy app i get an error and Can't figure out what is wrong.cookies, headers and authenticationin express I can do something like `res.cookie("name", "value")` for example. alternatively I can dtrpc hook pattern. This works, but I’m not convinced…I want to call my route when a button is clicked and have access to isLoading, onError etc… I have i