kosilica
kosilica16mo 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
kosilicaOP16mo 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
pvman6mo 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.