Skip to content

Add guidance for using wrangler types with Hono (--env-interface required) #842

@niklasfjeldberg

Description

@niklasfjeldberg

The Hono docs don't mention that Hono users need --env-interface to avoid a naming collision.

wrangler types generates a global interface Env by default. Hono also exports its own Env type ({ Bindings?: {}; Variables?: {} }). When a Hono app uses the generated Env as Bindings, TypeScript can resolve to the wrong Env, causing all binding properties to be missing.

The fix is straightforward — use a different interface name:

wrangler types --env-interface CloudflareBindings
const app = new Hono<{ Bindings: CloudflareBindings }>()

The Hono getting started docs at hono.dev only show manually defining bindings types, so a mention of wrangler types --env-interface there would also help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions