kosilica
kosilica11mo ago

useContext won't infer type from tRPC client

I am calling tRPC endpoints from my app and it's working flawlessly. As you can see on first screenshot it offers me autocompletion and queries return data from the server. However on some other places I would like to read data from tRPC's global state using context. Following code works & I can get the data but there is no typesafety for useContext and also auto complete on utils thinks it is of string type (2nd screenshot).
const utils = apiClient.useContext();
const profileData = utils.user.getUserProfile.getData();
const utils = apiClient.useContext();
const profileData = utils.user.getUserProfile.getData();
Does anyone has idea what I am doing wrong? Please note that I am not going to use useQuery() and useContext() lines at the same spot, I just put them in same place for screenshots.
No description
No description
2 Replies
kosilica
kosilica11mo ago
Managed to solved it. useContext was interpreted as following string as this is one of its types when some procedure returns any type The property '${any}' in your router collides with a built-in method, rename this router or procedure on your backend. I deleted old code that is not used anymore and it worked out of box along auto complete and all other benefits.
No description
pvman
pvman2mo ago
Do you mind sharing what old code did you delete? I'm using trpc 10.45.2 and have this error when trying to use useUtils. I also get The property '${any}' in your router collides with a built-in method, rename this router or procedure on your backend. and my trpc queries/mutations work just fine.
More Posts
Forward client headers with createTRPCProxyClient & Server-Side HelpersWith `createTRPCNext` i had the option to tap into the `context.req` object nextjs passed in, but I I have a websocket + REST project. Should I be using splitLink like this to combine WS and HTTP?I have a backend project that uses REST for queries/mutations and Websockets for subscriptions. I jNested procedures are separated by dots, is there a way to change that to `/`s instead ?currently it looks something like this `/api/trpc/post.byId`, is there a way to have it like `/api/tIs there a way to split a trpc api across multiple lambdas ?How do I go about splitting my TRPC api across multiple lambdas, such that each lambda would load thCan I alter the context in a procedure?Is there a proper way to do this? Mutating the `opts.ctx` directly seems wrongtRPC & getInitialPropsSo I am not using Next new App router but cant figure it out how to call a method during SSR with geGetting 413 error in Vercel when batching several queries (using Next pages router)Hi guys, I'm having a weird error on Vercel: "LAMBDA_RUNTIME Failed to post handler success responsQueries work but mutations do notOdd bug I'm experiencing with TRPC + react-query + the koa adapter. I just set everything up per docuseContext utils getData always returning undefinedI have my app set up with TRPC and when trying to call ` const utils = trpc.useContext();` `consTRPC Error HandlingI am using TRPC as my backend for my nextjs application. The one major problem i am facing is that,