Skip to content

Conversation

@dyyz1993
Copy link

Summary

Fixes Hono RPC type inference issue when using zValidator with partial schemas (e.g., schema.partial()).

Problem

When using zValidator('json', schema.partial()), the json field becomes optional in the middleware's Input type because HasUndefined<In> returns true when all fields are optional. This causes Hono RPC to not infer the json parameter for the client.

// Before: Client type inference fails
app.put('/:id', zValidator('json', schema.partial()), handler)
// Error: 'json' does not exist in type '{ param: { id: string } }'

Solution

Remove the HasUndefined check from DefaultInput type definition. This ensures:

  • The json field itself is always required in the Input type
  • The content within json can still be optional (e.g., { name?: string })
  • Hono RPC can correctly infer the parameter type
type DefaultInput<Target extends keyof ValidationTargets, In, Out> = {
  in: { [K in Target]: [In] extends [ValidationTargets[K]] ? In : InferInput<In, K> };
  out: { [K in Target]: Out };
};

Test Plan

  • Type checking passes
  • Works with partial schemas
  • Works with regular schemas
  • Hono RPC client correctly infers json parameter

Breaking Changes

None. The validation behavior remains unchanged; only the type inference is improved.

- Remove HasUndefined check from DefaultInput type
- This ensures Hono RPC can correctly infer json parameter type
- Fixes issue where schema.partial() breaks client type inference

Co-Authored-By: Claude <[email protected]>
@changeset-bot
Copy link

changeset-bot bot commented Jan 30, 2026

🦋 Changeset detected

Latest commit: be82f3b

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

This PR includes changesets to release 2 packages
Name Type
@hono/zod-validator Patch
@hono/zod-openapi 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 Jan 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.68%. Comparing base (3b38070) to head (be82f3b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1724   +/-   ##
=======================================
  Coverage   92.68%   92.68%           
=======================================
  Files         112      112           
  Lines        3734     3734           
  Branches      946      946           
=======================================
  Hits         3461     3461           
  Misses        245      245           
  Partials       28       28           
Flag Coverage Δ
zod-validator 91.30% <ø> (ø)

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.

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