honojs / hono

Web framework built on Web Standards
https://hono.dev
MIT License
16.93k stars 470 forks source link

Hono router generic type-errors if it receives an `interface` instead of a `type` #2981

Open scrawnyColeman opened 3 weeks ago

scrawnyColeman commented 3 weeks ago

What version of Hono are you using?

4.4.6

What runtime/platform is your app running on?

Cloudflare Pages

What steps can reproduce the bug?

Attempt to initialise Hono router with an interface. I have attempted to do so with cloudflare pages. The interface generated by wrangler looks as follows:

type Env = {
    DB: D1Database;
};

What is the expected behavior?

There should be no ts-error. This is an example of the type syntax

image

What do you see instead?

image

The following type-error appears:

Type '{ Bindings: Env; }' does not satisfy the constraint 'Env'.
  Types of property 'Bindings' are incompatible.
    Type 'Env' is not assignable to type 'Bindings'.
      Index signature for type 'string' is missing in type 'Env'.

Additional information

No response

scrawnyColeman commented 3 weeks ago

cc @RamIdeas

yusukebe commented 3 weeks ago

Hi @scrawnyColeman

This is not a real bug but a known issue related to TypeScript's limitations. Currently, we only have to write it as type. However, I also think it should be written with interface. So, let this issue be left as an enhancement.