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

Types: zValidator param validation makes input optional where it should be required #3227

Closed
MonsterDeveloper opened this issue Aug 1, 2024 · 1 comment · Fixed by #3229

Comments

@MonsterDeveloper
Copy link
Contributor

Reproduction:

  1. Given the exact same schema with 1 required field, create 2 validators: one for param, the other one for json:
const schema = z.object({ id: z.string() })

const paramValidator = zValidator("param", schema)

const jsonValidator = zValidator("json", schema)
  1. For the jsonValidator, the input type is inferred correctly: id is required
    CleanShot 2024-08-01 at 22 48 50@2x

  2. For the paramValidator, however, the id field in the input type is optional for an unknown reason, while it should be marked as required since the schema says it is not optional and not nullable:
    CleanShot 2024-08-01 at 22 50 45@2x

This example is not working as expected, i.e. accepts undefined as a param:
CleanShot 2024-08-01 at 22 51 52@2x

Suspected commit: honojs/middleware@4875e1c

Link to TS Playground

@yusukebe yusukebe transferred this issue from honojs/middleware Aug 3, 2024
@yusukebe
Copy link
Member

yusukebe commented Aug 3, 2024

Hi @MonsterDeveloper

Thank you for raising the issue. This is not only the Zod Validator issue. It is hono issue. I've transferred it as hono's issue.

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

2 participants