Repository navigation
🐛 BUG: wrangler types + DurableObjects + a build process + typescript
#16878
workers-devprod
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Moved from #6905. Originally opened by zwily on 2024-10-07.
Which Cloudflare product(s) does this pertain to?
Wrangler
What version(s) of the tool(s) are you using?
3.80.0 [wrangler]
What version of Node are you using?
20
What operating system and version are you using?
Mac Sequoia
Describe the Bug
I have a remix app using wrangler+static assets, and am also using a DurableObject. I have the DurableObject defined in my
wrangler.toml, and then runwrangler typesto generateworker-configuration.d.ts. That ends up looking something like this:That's great, except,
Env["DO"]actually is typed asDurableObjectNamespace<any>becauseimport("./build/index")is reading from my built javascript file and has no types. If I manually change that toimport("./server.ts").DrizzleTestDOthen typing works fine, but the change would be erased the next time I runwrangler types.Expected behavior
I'm not sure what the right thing to do here is. As a workaround, I am running
wrangler types --env-namespace EnvBeforeFixup, and then in myenv.d.tsoverriding with the appropriate type:This lets me have the correct type and not worry about overwriting it when I run
npm run typegenin the future.Example repo here: https://github.com/zwily/test-drizzle-durable-objects
Steps to reproduce
Please provide the following:
wrangler.tomlA git repo we can clone and run a test suite on, or which has a README with step-by-step instructions, is even better. In this case, please use the field below to provide a link to the minimal repro.
Please provide a link to a minimal reproduction
https://github.com/zwily/test-drizzle-durable-objects
Please provide any relevant error logs
No response
threepointone commented on 2024-10-07:
Maybe
wrangler typesshould accept an entrypoint, so you could saywrangler types --entry src/index.ts.zwily commented on 2024-10-07:
Yes, that would do it. Want me to submit a PR?
threepointone commented on 2024-10-08:
Tagging @andyjessop, I'll let the team take a call there.
penalosa commented on 2024-11-08:
Adding an entrypoint to
wrangler typessounds like a good solution here—PRs welcome @zwily!gabrielf commented on 2026-02-20:
I had a similar problem which was that the types were correct as long as the DurableObject class resided in the main worker file but not when it was in a separate file. I solved it by re-exporting the DurableObject class from the worker file. I guess that would not work for the problem in this issue but it may be helpful to others that have similar issues.
All reactions