`wrangler types` breaks VS Code typing

I ran pnpm wrangler types (Wrangler 4.40.1) and it added a new GlobalProps interface to my worker-configuration.d.ts. This appears to break types in VS Code - I now get Property 'Foo' does not exist on type 'Env' errors for all my bindings and environment variables (screenshot). Manually editing worker-configuration.d.ts to remove the GlobalProps import makes the VS Code errors go away. How can I fix?
No description
No description
18 Replies
olafg
olafg•2mo ago
Can you share a full screenshot of the interface Env generated by Wrangler? Starts at line 8 in your worker-configuration.d.ts
Matthew
MatthewOP•2mo ago
No description
olafg
olafg•2mo ago
Alright, thanks! I just wanted to ensure that the binding type was correctly generated I avoid adding manual edits to the worker-configuration.d.ts file as it will be overwritten if you generate new types and bindings with Wrangler. What do you want to acheive by adding the GlobalProps interface?
Matthew
MatthewOP•2mo ago
wrangler is adding GlobalProps, not me. My screenshot shows the output of wrangler types, diffed against the previous (working) version. To try and investigate the issue, I manually edited the worker-configuration.d.ts to remove GlobaProps interface, and typing immediately reappeared in VS Code.
olafg
olafg•2mo ago
Ah, you're right. Let me see if I can reproduce this in a worker project on my end I bumped my Worker project to latest wrangler and generated types, but I am not seeing the issue on my end. What does your Worker Entrypoint look like (src/index)?
Matthew
MatthewOP•2mo ago
Not sure I can post it all, but the entrypoint is below - then fetch and scheduled are ExportedHandlerFetchHandler<Env> and ExportedHandlerScheduledHandler<Env> functions.
import * as Sentry from "@sentry/cloudflare"

export default Sentry.withSentry(
(env) => ({
dsn: env.PUBLIC_SENTRY_DSN,
autoSessionTracking: false,
sendClientReports: false,
beforeSend: (event: Sentry.ErrorEvent, hint: Sentry.EventHint) => {
console.log(hint.originalException || hint.syntheticException)
return event
},
}),
{
fetch,
scheduled: async (controller, env, ctx) =>
Sentry.withMonitor(SENTRY_MONITOR_SLUG, () => scheduled(controller, env, ctx)),
} satisfies ExportedHandler<Env>
)
import * as Sentry from "@sentry/cloudflare"

export default Sentry.withSentry(
(env) => ({
dsn: env.PUBLIC_SENTRY_DSN,
autoSessionTracking: false,
sendClientReports: false,
beforeSend: (event: Sentry.ErrorEvent, hint: Sentry.EventHint) => {
console.log(hint.originalException || hint.syntheticException)
return event
},
}),
{
fetch,
scheduled: async (controller, env, ctx) =>
Sentry.withMonitor(SENTRY_MONITOR_SLUG, () => scheduled(controller, env, ctx)),
} satisfies ExportedHandler<Env>
)
I also have a separate, much simpler Worker project - just a fetch handler which responds with data from an R2 bucket. In that project, running wrangler types also outputs this GlobalProps interface - but it doesn't cause any problems, VS Code typing is fine, bindings are picked up
olafg
olafg•2mo ago
Does that project also use Sentry?
Matthew
MatthewOP•2mo ago
I did recently install this package https://www.npmjs.com/package/cloudflare and wonder if there's maybe some namespace issue? nope
olafg
olafg•2mo ago
Just to try to pinpoint the the issue, if you remove the Sentry export and just keep the minimal fetch and scheduled exports, does that change anything?
Matthew
MatthewOP•2mo ago
nope
olafg
olafg•2mo ago
Hmm, I am not sure, hard to debug without being able to reproduce. Perhaps someone with more in-depth knowledge of the type generation can help if they see this.
Matthew
MatthewOP•2mo ago
thanks. do you know if there's anywhere i should be looking for logs of type generation errors? the Output > Typescript pane in VS Code doesn't have anything
sebws
sebws•2mo ago
hello, I have also faced this issue @Olaf | CDN/Developer Platform I have a reproduction here. https://github.com/sebws/cf-sentry-issue-repo @Matthew have you had any luck with this?
GitHub
GitHub - sebws/cf-sentry-issue-repo
Contribute to sebws/cf-sentry-issue-repo development by creating an account on GitHub.
Matthew
MatthewOP•2mo ago
ah good work creating a repro! maybe this should be reported to sentry, if it's increasingly looking like a sentry issue no i did nothing more - just commented out GlobalProps for now 😬
sebws
sebws•2mo ago
i suppose I can do that 😋 i just realised i dont think the extra library with cloudflare types installed was necessary for showing the error. makes it seem very Sentry related
sebws
sebws•2mo ago
olafg
olafg•2mo ago
Hi! I tried your test and was unable to reproduce the error using pnpm, not sure what's going on but I've never seen this error in any of projects. Seems like someone faced this a while ago and reported it to Sentry on github
sebws
sebws•2mo ago
hey, curious that you couldn't reproduce, but it seems to me that the github sentry issue is the same. they are saying that for it to be fixed, their prs fixing cloudflare types need to be fixed. not sure if that's true or not but 🤷

Did you find this page helpful?