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

Hono treats empty object {} as type never for RPC #3868

Open
meows opened this issue Jan 29, 2025 · 1 comment · May be fixed by #3873
Open

Hono treats empty object {} as type never for RPC #3868

meows opened this issue Jan 29, 2025 · 1 comment · May be fixed by #3873
Labels

Comments

@meows
Copy link

meows commented Jan 29, 2025

What version of Hono are you using?

4.6.19

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

Bun

What steps can reproduce the bug?

Create any route and simply return c.json({}). It will be inferred as type never.

const app = new Hono()
app.get("/", async (c) => c.json({}))

This behavior is specified in the source code:

{
  json(): F extends "text" 
    ? Promise<never> 
    : F extends "json" 
      ? Promise<BlankRecordToNever<T>> 
      : Promise<unknown>
}

This makes no sense as {} is valid JSON, and the response at the other end is in fact {} and not never.

What is the expected behavior?

This behavior is very surprising because this is valid JSON being mistyped. This behavior should at least be very clearly specified in the docs.

What do you see instead?

No response

Additional information

No response

@meows meows added the triage label Jan 29, 2025
@yusukebe yusukebe added bug and removed triage labels Jan 31, 2025
@yusukebe yusukebe linked a pull request Jan 31, 2025 that will close this issue
4 tasks
@yusukebe
Copy link
Member

HI @meows

This is a bug. #3868 can fix it. This is not a breaking change, but It may affect some users. So, it will be included in the next minor release instead of a patch release. Thank you!

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