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

fix(factory): relax Bindings and Variables for createMiddleware #3498

Merged
merged 2 commits into from
Oct 10, 2024

Conversation

yusukebe
Copy link
Member

@yusukebe yusukebe commented Oct 8, 2024

If there were type mismatches regarding Bindings and Variables with nested middleware created by createMiddleware, it threw the error. I've fixed it does not throw the type error.

type Bindings = {
  MY_VAR_IN_BINDINGS: string
}

const app = new Hono<{ Bindings: Bindings }>()

type Variables = {
  MY_VAR: string
}
const middleware = (_variable: string) =>
  createMiddleware<{ Variables: Variables }>(async (c, next) => {
    await next()
  })

app.get(
  '/',
  createMiddleware<{ Bindings: Bindings }>(async (c, next) => {
    const mw = middleware(c.env.MY_VAR_IN_BINDINGS)
    await mw(c, next) // `c` does not throw an error
  }),
  (c) => {
    return c.json({})
  }
)

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

@yusukebe yusukebe changed the title feat(factory): relax Bindings and Variables types feat(factory): relax Bindings and Variables for createMiddleware Oct 8, 2024
Copy link

codecov bot commented Oct 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.58%. Comparing base (31b4cd4) to head (f2e0059).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3498   +/-   ##
=======================================
  Coverage   95.58%   95.58%           
=======================================
  Files         155      155           
  Lines        9357     9357           
  Branches     2730     2764   +34     
=======================================
  Hits         8944     8944           
  Misses        413      413           

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

@yusukebe yusukebe changed the title feat(factory): relax Bindings and Variables for createMiddleware fix(factory): relax Bindings and Variables for createMiddleware Oct 10, 2024
@yusukebe yusukebe marked this pull request as ready for review October 10, 2024 20:20
@yusukebe yusukebe merged commit d5166dd into main Oct 10, 2024
16 checks passed
@yusukebe yusukebe deleted the feat/factory-relax-bindings-variables-types branch October 10, 2024 20:42
yusukebe added a commit that referenced this pull request Oct 14, 2024
@yusukebe yusukebe mentioned this pull request Oct 14, 2024
4 tasks
yusukebe added a commit that referenced this pull request Oct 15, 2024
TinsFox pushed a commit to TinsFox/hono that referenced this pull request Oct 28, 2024
…nojs#3498)

* feat(factory): relax Bindings and Variables types

* add a break
TinsFox pushed a commit to TinsFox/hono that referenced this pull request Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant