T3 Stack: tRPC not extending type definitions to client

Hey, I'm currently trying to work on getting my 'next build' script to work and ran into a bunch of issues when I'm using data from tRPC calls. The variables I'm saving the data under are not receiving the type inference benefits that I thought I would be getting with tRPC but instead being set to any type. To try and resolve this I looked into the tRPC docs and saw that you can use your root appRouter to create type inference from the subroute calls you make so I set about adding that to my application. It allowed me to get through all of the "unexepected any" errors with my next build script but out of the blue I started getting circular dependency issues with the tRPC type inference that I've built out and all of my tRPC calls on the client are now throwing errors. Has anyone experienced a similar issue or think they may have a solution as I have exhausted my own capabilities?
10 Replies
cje
cje8mo ago
screenshots are not useful. gonna need a minimal reproduction to be able to tell you anything here.
Chuuy
ChuuyOP8mo ago
I'm currently working off of this branch: https://github.com/gsayre/tournamate/tree/feature/tou-48. Sorry I don't know how to create a minimal reproduction as I don't fully understand what is happening here 😔 Almost all of my components in the components directory under src have some kind of tRPC call and I did my type inference exporting under server/trpc/exportedTypes.ts. Let me know if there is any other information that I can give to help for context
cje
cje8mo ago
(watch the timestamp) The point of creating a minimal reproduction is that you figure out where it starts breaking
Chuuy
ChuuyOP8mo ago
Sorry, I did not mean to offend or be inconsiderate in any way. This is my first time reaching out for help outside of work and first experience with any form of open source communication. I appreciate the explanation and your time to get this resource to me. I will get to work on trying to create a codesandbox or small example repo like detailed in the video after I finish work today. I appreciate the help and again I apologize if this came off the way described in the video
Chuuy
ChuuyOP8mo ago
Hey, I created the minimal reproduction in codesandbox. It seems to be having some issues with the "@types/react" where the AppProps don't seem to be working but that is not an issue that I have in my repo. I think the important piece is that it is showing all of the errors that I'm experiencing with trpc in the virtual editor environment
cje
cje8mo ago
on first look there are a bunch of issues that aren't related to your problem - _app.ts isn't importing helloRouter - trpc.ts refers to a context that doesn't exist - index.tsx refers to a procedure that doesn't exist on the router my suggestion would be pnpm create t3-app@latest, if you pick trpc, tailwind, and pages router it should be basically the same thing as your minimal repro, except it works. find the difference.
Chuuy
ChuuyOP8mo ago
Hey, I appreciate all of your help but I don't think I'm getting anywhere with the issue after messing around with things for a couple days. I followed your suggestions and created a new t3-app@latest and then deprecated the versions to try and recreate the situation that I'm currently in and only found that a bunch of errors come from what I assume to be methods that exist in the v11 of tRPC and not in v10 which I'm currently on. Tried cleaning that up but ended up with the same error which I cannot pinpoint exactly where it comes from. From what I assume it has something to do with my _app.ts folder in my trpc server folder has an 'any' definition for the appRouter that we create and export to create the tRPCNextClient which will be consumed by the client side of my application. The router (from trpc.ts in trpc server directory) that I import in the _app.ts file is properly typed when I hover over with the BuiltRouter<etc...> but variable I am saving this router to, appRouter, has implicity a type of 'any'. This is where I believe the error to be occurring. I don't exactly know what I did to cause this but as a result I have tried doing patch, minor and major upgrades of tRPC using the "npx ncu" command and despite it being on an updated version of the library I am still getting these type errors where the appRouter is coming back as 'any' type.
Chuuy
ChuuyOP8mo ago
I tried to do some more digging to see if anyone else was having issues with this error and found a couple pages and came across this page (https://github.com/trpc/trpc/issues/5614) which seems to include all of the reproductions similar to what I was experiencing except within a monorepo with a shared tRPC package instead of my create-t3-app. He mentions a bit about how there were problems probably caused by the fact he used commonjs in his server but I'm using esnext which is the suggested compiler option and still getting these issues. So I dug deeper into the linked issues (https://github.com/trpc/trpc/issues/3496). It seems he explicitly re-exported these types from the "trpc's unstable-core-do-not-import" package in his index.ts (https://github.com/akashdevcc/zero-stack/blob/main/packages/trpc/src/index.ts, lines 24-32) file which resolved those issues for him and caused the type inference issues to go away. I'm going to try the same thing and see if it resolves my problems as well and will report back because I've been pretty heads down on this just trying to get some kind of different error I can work off of. If that doesn't work then I'm going to create a new t3-turbo app and incrementally migrate all of my current project into the new one and hopefully through that I'll see where the problem may have been or maybe it will get resolved in a different project with updated dependencies.
GitHub
bug: Getting "property collision with a built-in method" in client ...
Provide environment information System: OS: Linux 6.5 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish) CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz Memory: 2.58 GB / 15.48 GB Container: Y...
GitHub
Issues · trpc/trpc
🧙‍♀️ Move Fast and Break Nothing. End-to-end typesafe APIs made easy. - Issues · trpc/trpc
Chuuy
ChuuyOP8mo ago
Thank you for all the help and I'll update this thread if I end up resolving the issue one way or another so that if someone else runs into the same issue they can stumble across this!
Want results from more Discord servers?
Add your server