T
tRPC

useContext won't infer type from tRPC client

useContext won't infer type from tRPC client

Kkosilica8/22/2023
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
Kkosilica8/22/2023
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

Looking for more? Join the community!

T
tRPC

useContext won't infer type from tRPC client

Join Server