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

factory.createMiddleware() breaks the client's typing. #3847

Closed
satoshun00 opened this issue Jan 23, 2025 · 3 comments · Fixed by #3849
Closed

factory.createMiddleware() breaks the client's typing. #3847

satoshun00 opened this issue Jan 23, 2025 · 3 comments · Fixed by #3849
Labels

Comments

@satoshun00
Copy link

What version of Hono are you using?

4.6.17

What runtime/platform is your app running on? (with version if possible)

Node

What steps can reproduce the bug?

When using middleware created with factory.createMiddleware() in .use, the client's type inference stops working.

Previously, an issue was reported regarding createMiddleware() at #3122, which seems to have been fixed. However, it appears a similar issue is occurring with factory.createMiddleware().

Below is a code example for reproduction:
TypeScript playground

import { Hono, type Env } from 'hono';
import { hc } from 'hono/client';
import { createFactory, createMiddleware } from 'hono/factory';

const factory = createFactory<Env>();

const middleware = factory.createMiddleware(async (_, next) => {
  console.log('Middleware');
  await next();
});

// There will be no type errors when creating middleware with createMiddleware()
// const middleware = createMiddleware(async (_, next) => {
//   console.log('Middleware');
//   await next();
// });

const app = new Hono()
  .use('*', middleware)
  .get('/users', (c) => c.text('GET /users'));

const client = hc<typeof app>('');
console.log(client.users.$get()); // This should typecheck

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

@yusukebe yusukebe added bug and removed triage labels Jan 23, 2025
@yusukebe
Copy link
Member

Hi @satoshun00 Thanks! This is a bug. I'll fix it.

@yusukebe
Copy link
Member

@satoshun00

This may be fixed in the new version v4.6.18. Can you try it?

@satoshun00
Copy link
Author

@yusukebe
Thank you for the quick response!
I have confirmed that the fix works in my project as well.

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 a pull request may close this issue.

2 participants