Skip to content

Conversation

@miyaji255
Copy link
Contributor

Summary

I would like to apologize for mistakenly treating undefined as a Response in the previous PR.

Typically, it's ({ success: true }) => undefined, ({ success: false }) => Response, and undefined should be ignored. This PR will simply remove the undefined.

  • Add tests
  • Run tests
  • yarn changeset at the top of this repo and push the changeset
  • Follow the contribution guide

@changeset-bot
Copy link

changeset-bot bot commented Dec 1, 2025

🦋 Changeset detected

Latest commit: dc7fd19

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@hono/standard-validator Patch
@hono/valibot-validator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov
Copy link

codecov bot commented Dec 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.55%. Comparing base (02ab9e8) to head (dc7fd19).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1589   +/-   ##
=======================================
  Coverage   84.55%   84.55%           
=======================================
  Files         118      118           
  Lines        3845     3845           
  Branches     1037     1037           
=======================================
  Hits         3251     3251           
  Misses        503      503           
  Partials       91       91           
Flag Coverage Δ
standard-validator 1.92% <ø> (-0.39%) ⬇️
valibot-validator 0.28% <ø> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yusukebe
Copy link
Member

yusukebe commented Dec 2, 2025

Hi @miyaji255

Thank you for the PR!

I think that the code I pointed to with the following code is not typed as expected. What do you think of it?

import { number, object } from 'valibot'
import { Hono } from 'hono'
import { vValidator } from '@hono/valibot-validator'
import { hc } from 'hono/client'

const app = new Hono()
const schema = object({
  id: number()
})
const route = app.post(
  '/post',
  vValidator('json', schema, (result, c) => {
    if (!result.success) {
      // Comment out below
      // return c.json(`Invalid Post ID: ${result.output}` as const, 400)
    }
  }),
  (c) => {
    const data = c.req.valid('json')
    return c.json(data, 200)
  }
)

const client = hc<typeof route>('/')
const res = await client.post.$post({ json: { id: 123 } })

if (res.status === 200) {
  const data = await res.json()
} else {
  const data = await res.json() // <== { id: number } is correct???
}

export default app

@miyaji255
Copy link
Contributor Author

At the type level, there's no distinction between success undefined and failure undefined. That's why I gave up.

Therefore, I'm exporting FailedResponse to allow explicit type annotations like this:

const route = app.post(
  '/post',
  vValidator('json', schema, (result, c) => {
    if (!result.success) {
      // Uncomment below
      // return c.json(`Invalid Post ID: ${result.output}` as const, 400)
      return undefined as unknown as FailedResponse<typeof schema>;
    }
  }),
  (c) => {
    const data = c.req.valid('json')
    return c.json(data, 200)
  }
)

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.

2 participants