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] TypeScript Binding Generation doesn't work #238

Closed
wesbos opened this issue Jan 8, 2025 · 3 comments
Closed

[BUG] TypeScript Binding Generation doesn't work #238

wesbos opened this issue Jan 8, 2025 · 3 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@wesbos
Copy link
Contributor

wesbos commented Jan 8, 2025

Describe the bug

I'm using npx wrangler types --experimental-include-runtime to generate my binding types, which creates a worker-configuration.d.ts file in the root of my project that looks like this:

// Generated by Wrangler by running `wrangler types --experimental-include-runtime`

interface Env {
	OG: KVNamespace;
	DB: D1Database;
	ASSETS: Fetcher;
}

Now the types for (await getCloudflareContext()).env. look like this

Screenshot 2025-01-08 at 4 48 48 PM

Because this package ships then like this:

declare global {
    interface CloudflareEnv {
        NEXT_CACHE_WORKERS_KV?: KVNamespace;
        ASSETS?: Fetcher;
    }
}

If I rename the generated types to CloudflareEnv I see everything:

Screenshot 2025-01-08 at 4 50 04 PM

So either this package or the wrangler types command need to agree on the Env / CloudflareEnv naming?

Steps to reproduce

see above

Expected behavior

see above

@opennextjs/cloudflare version

0.3.4

Wrangler version

3.99.0

next info output

15.1.2

Additional context

No response

@wesbos wesbos added bug Something isn't working triage labels Jan 8, 2025
@vicb vicb added documentation Improvements or additions to documentation and removed triage labels Jan 9, 2025
@vicb
Copy link
Contributor

vicb commented Jan 9, 2025

The cf-typegen npm script generated by the template is wrangler types --env-interface CloudflareEnv env.d.ts.

You can use wrangler types --experimental-include-runtime --env-interface CloudflareEnv env.d.ts

Leaving this open until we improve the doc

@wesbos
Copy link
Contributor Author

wesbos commented Jan 9, 2025

ahh awesome thank you!

@vicb
Copy link
Contributor

vicb commented Jan 14, 2025

Sent a PR to the docs

@vicb vicb closed this as completed Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants