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

fix(standard-validator): fix hook's result type #964

Merged
merged 2 commits into from
Feb 10, 2025

Conversation

paihu
Copy link
Contributor

@paihu paihu commented Feb 8, 2025

fix type error

import { Hono } from "hono";
import { minLength, object, pipe,  string } from "valibot";

const createSchema = object({
  name: pipe(string(), minLength(3)),
});

const route = new Hono()
  .post(
    "/",
    sValidator("form", createSchema, (result, c) => {
      if (!result.success) {
        return c.json({ errors: result.error }, 400);  // <- type error
      }
    }),
    async (c) => {
      const { name } = c.req.valid("form");
      return c.json({name});
    }
  );
Property 'error' does not exist on type '({ success: boolean; data: { name: string; }; } | { success: boolean; error: readonly Issue[]; data: { name: string; }; }) & { target: "form"; }'.
  Property 'error' does not exist on type '{ success: boolean; data: { name: string; }; } & { target: "form"; }'

The author should do the following, if applicable

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

Copy link

changeset-bot bot commented Feb 8, 2025

🦋 Changeset detected

Latest commit: bc6b500

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

This PR includes changesets to release 1 package
Name Type
@hono/standard-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

Copy link
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yusukebe
Copy link
Member

Hi @paihu

I added a test and formatted the code. Looks good! Thank you!

@yusukebe yusukebe merged commit 352507b into honojs:main Feb 10, 2025
1 check passed
@github-actions github-actions bot mentioned this pull request Feb 10, 2025
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