`interface GlobalProps` breaks my typechecking
What versions & operating system are you using?
Windows WSLv2 System: OS: Linux 6.6 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish) CPU: (16) x64 AMD Ryzen 7 7840H w/ Radeon 780M Graphics Memory: 11.42 GB / 15.22 GB Container: Yes Shell: 5.8.1 - /usr/bin/zsh Binaries: Node: 20.15.0 - /home/shmuli/.nvm/versions/node/v20.15.0/bin/node npm: 10.9.2 - /home/shmuli/.nvm/versions/node/v20.15.0/bin/npm pnpm: 10.12.1 - /home/shmuli/.local/share/pnpm/pnpm bun: 1.1.38 - /home/shmuli/.bun/bin/bun
Please provide a link to a minimal reproduction
i dont have one
Describe the Bug
I recently upgraded wrangler and friends to latest versions and noticed a new type in worker-configuration.d.ts
I have a fairly complex monorepo with types defined and imported all over the place, but this line seems to break my typechecking
interface GlobalProps {
mainModule: typeof import("./src/index");
}
commenting it out fixes my typechecking
Please provide any relevant error logs
No response
Hi. We haven't been able to reproduce this issue. Could you share a minimal reproduction and the TypeScript error messages? This will help us debug this.
Thanks!
Hi. I created a repro repo here
To repro run:
pnpm i && pnpm run typecheck
The typecheck will fail.
Now, comment out the interface defined in the worker-config file ( /packages/types/src/worker-configuration.d.ts)
Rerun typecheck and it's all green
pnpm run typecheck
Could you please paste the exact error message in the thread, so not everyone has to run the repro to see it?
Also can you share exactly the command you run to generate the worker-configuration.d.ts, including what directory you run it from?
I haven't run the repro, but I notice it looks like you store your worker-configuration.d.ts in a different package from the worker main module, and I'm guessing that's the problem. The generated GlobalProps looks like:
declare namespace Cloudflare {
interface GlobalProps {
mainModule: typeof import("../../../apps/web/workers/app");
}
But this is trying to import a file from some other package. I guess that's what doesn't work (but still, please post the info to confirm).
I am not really sure if worker-configuration.d.ts is intended to be possible to put in a separate package from the worker itself. @penalosa what do you think?
You are correct that the worker types are being generated into a different package. This is so I can share the types more easily with other packages (I simplified them out for the repro though)
I am not surprised that this isn';t an expected use case, but it is handy. An opt out of the GlobalProps import would be a workable solution, similar to how I opt out of strict vars on the command line
The command to generate the cf types is in the package.json of the apps/web, it is:
"cf-typegen": "wrangler types ../../packages/types/src/worker-configuration.d.ts --strict-vars false",
The type error, when running pnpm run typecheck in the root of the repo (this uses turbo to run the typecheck command in each of the packages in the repo, so it runs in apps/web and also packages/types):
~/code/bug-repro > pnpm run typecheck
> @bug-repro/root@ typecheck /home/shmuli/code/bug-repro
> turbo run typecheck
turbo 2.6.1
• Packages in scope: @bug-repro/types, @bug-repro/typescript-config, @bug-repro/web
• Running typecheck in 3 packages
• Remote caching disabled
┌─ @bug-repro/types#typecheck > cache miss, executing 236d504bdc728d89
> @bug-repro/[email protected] typecheck /home/shmuli/code/bug-repro/packages/types
> tsc --noEmit
../../apps/web/workers/app.ts:13:16 - error TS2307: Cannot find module 'virtual:react-router/server-build' or its corresponding type declarations.
13 () => import("virtual:react-router/server-build"),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../apps/web/workers/app.ts:14:15 - error TS2339: Property 'env' does not exist on type 'ImportMeta'.
14 import.meta.env.MODE
~~~
Found 2 errors in the same file, starting at: ../../apps/web/workers/app.ts:13
ELIFECYCLE Command failed with exit code 2.
command finished with error: command (/home/shmuli/code/bug-repro/packages/types) /home/shmuli/.local/share/pnpm/.tools/@pnpm+linux-x64/9.0.0/bin/pnpm run typecheck exited (2)
└─ @bug-repro/types#typecheck ──
@bug-repro/types#typecheck: command (/home/shmuli/code/bug-repro/packages/types) /home/shmuli/.local/share/pnpm/.tools/@pnpm+linux-x64/9.0.0/bin/pnpm run typecheck exited (2)
Tasks: 0 successful, 1 total
Cached: 0 cached, 1 total
Time: 2.072s
Failed: @bug-repro/types#typecheck
ERROR run failed: command exited (2)
ELIFECYCLE Command failed with exit code 2.
Or in image form: