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

feat(types): allow passing interfaces as Bindings / Variables #3136

Merged
merged 6 commits into from
Jul 16, 2024

Conversation

ottomated
Copy link
Contributor

This changes the type of Bindings and Variables from Record<string, unknown> to object.

Pro:

  • Allows interfaces to be used like so:
interface Env {
  KV: KVNamespace;
}
// would error before
const app = new Hono<{ Bindings: Env }>();

Con:

  • Looser type - any non-primitive could hypothetically be passed in
// no error
const app = new Hono<{ Bindings: string[] }>();

In my opinion, this trade-off is worth it because Cloudflare's wrangler types command generates output like this:

// Generated by Wrangler
// After adding bindings to `wrangler.toml`, regenerate this interface via `npm run cf-typegen`
interface Env {
  KV: KVNamespace;
}

Fixes #2981

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

Copy link

codecov bot commented Jul 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.18%. Comparing base (9987b59) to head (3b753d8).

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #3136   +/-   ##
=======================================
  Coverage   96.18%   96.18%           
=======================================
  Files         151      151           
  Lines       15030    15034    +4     
  Branches     2646     2736   +90     
=======================================
+ Hits        14456    14460    +4     
  Misses        574      574           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yusukebe yusukebe changed the base branch from main to next July 16, 2024 12:00
@yusukebe yusukebe added the v4.5 label Jul 16, 2024
@yusukebe yusukebe changed the base branch from next to main July 16, 2024 12:00
@yusukebe yusukebe changed the base branch from main to next July 16, 2024 12:12
@yusukebe
Copy link
Member

Hi @ottomated !

I've updated your branch to follow the next branch for the next minor release v4.5.0. I'll merge this now. Thank you for your contribution!

@yusukebe yusukebe merged commit 1cee728 into honojs:next Jul 16, 2024
14 checks passed
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hono router generic type-errors if it receives an interface instead of a type
2 participants