Weird data type when extending context in fetch adapter
Environment:
* pnpm
* Vite react SPA
* Node v22.11.0
* tRPC server and client version: 11.0.0-rc.828
* Using tRPC with tanstack query (and the new integration approach)
I realise that "weird" is a really bad descriptor, but I honestly don't know what else to call it.
I'm using the fetch adapter with CF workers and needed cloudflare's env in my context, I added this like such:
Now this works wonders, I get access to the cloudflare env in my procedures via context and can use KV bindings from there, very nice! Unfortunately the type from the client is very odd, specifically it considers the data from my query to be of type:
As in the following:
Now, this purely from a type pespective, the actual value is there during runtime and works fine. But obviously as soon as the code gets type checked it throws a fit because it thinks I'm trying ot access
Any help is greatly appreciated!
* pnpm
* Vite react SPA
* Node v22.11.0
* tRPC server and client version: 11.0.0-rc.828
* Using tRPC with tanstack query (and the new integration approach)
I realise that "weird" is a really bad descriptor, but I honestly don't know what else to call it.
I'm using the fetch adapter with CF workers and needed cloudflare's env in my context, I added this like such:
Now this works wonders, I get access to the cloudflare env in my procedures via context and can use KV bindings from there, very nice! Unfortunately the type from the client is very odd, specifically it considers the data from my query to be of type:
(() => never) | undefinedAs in the following:
Now, this purely from a type pespective, the actual value is there during runtime and works fine. But obviously as soon as the code gets type checked it throws a fit because it thinks I'm trying ot access
val on that type.Any help is greatly appreciated!
Solution
Well, in case anyone sees this I managed to figure it out. When starting a new CF project with the react framework template it creates an additional tsconfig (to the three existing ones from vite). This config (
and the first two also need to be referenced in
tsconfig.worker.json) references the following types:and the first two also need to be referenced in
tsconfig.app.json for the files in the src directory to pick up on it. Adding those two removes the issue and allows the types to be inferred correctly