honojs / middleware

monorepo for Hono third-party middleware/helpers/wrappers
https://hono.dev
475 stars 169 forks source link

zValidator types not working with rpc client query #707

Open wststone opened 3 months ago

wststone commented 3 months ago

image image image As shown in the screenshots above, the rpc client query paramters should have the correct inferred number type.

package version: "hono": "^4.5.4" "@hono/zod-validator": "^0.2.2"

cybercoder-naj commented 2 months ago

Bump! I have the same issue.

yusukebe commented 2 months ago

Hi @wststone @cybercoder-naj

The Zod Validator uses z.input to infer a query using the request type. With it, the value with z.coerce will have undefined and optional:

CleanShot 2024-09-10 at 16 10 58@2x

This means the value defined z.coerce can be optional or undefined. On the other hand, if you specify the value with z.number(), it can not allow undefined.