Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 BUG: wrangler types + DurableObjects + a build process + typescript #6905

Open
zwily opened this issue Oct 7, 2024 · 3 comments
Open
Assignees
Labels
bug Something that isn't working

Comments

@zwily
Copy link
Contributor

zwily commented Oct 7, 2024

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 run wrangler types to generate worker-configuration.d.ts. That ends up looking something like this:

interface Env {
	DO: DurableObjectNamespace<import("./build/index").DrizzleTestDO>;
}

That's great, except, Env["DO"] actually is typed as DurableObjectNamespace<any> because import("./build/index") is reading from my built javascript file and has no types. If I manually change that to import("./server.ts").DrizzleTestDO then typing works fine, but the change would be erased the next time I run wrangler 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 my env.d.ts overriding with the appropriate type:

interface Env extends EnvBeforeFixup {
  DO: DurableObjectNamespace<import("./app/do").DrizzleTestDO>;
}

This lets me have the correct type and not worry about overwriting it when I run npm run typegen in the future.

Example repo here: https://github.com/zwily/test-drizzle-durable-objects

Steps to reproduce

Please provide the following:

  • A minimal working subset of your worker code
  • A minimal working subset of your wrangler.toml
  • Commands used to start your local dev server, including custom env and cli args
  • Steps to be performed in the browser, curl commands, or a test we can run that reliably fails (at least a percent of the time)

A 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

@zwily zwily added the bug Something that isn't working label Oct 7, 2024
@zwily zwily changed the title 🐛 BUG: wrangler types + DurableObjects + a build process 🐛 BUG: wrangler types + DurableObjects + a build process + typescript Oct 7, 2024
@threepointone
Copy link
Contributor

Maybe wrangler types should accept an entrypoint, so you could say wrangler types --entry src/index.ts.

@zwily
Copy link
Contributor Author

zwily commented Oct 7, 2024

Maybe wrangler types should accept an entrypoint, so you could say wrangler types --entry src/index.ts.

Yes, that would do it. Want me to submit a PR?

@threepointone
Copy link
Contributor

Tagging @andyjessop, I'll let the team take a call there.

@emily-shen emily-shen assigned emily-shen and andyjessop and unassigned emily-shen Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
Status: Backlog
Development

No branches or pull requests

4 participants