Skip to content

Create exact error message for z.array().length(). #1611

@john-schmitz

Description

@john-schmitz

Given this schema:

const testSchema = z.array(z.number()).length(4);

For arrays with less than 4 elements, it returns the message:

Should have at least 4 items

For arrays with more than 4 elements, it returns the message:

Should have at most 4 items

I wish instead for it to return a message explaining that it should be precisely 4 items:

Should have exactly 4 items

I know I could achieve that with a custom refine validation, but it would be nice to have it baked in.

Of course, if you find this suggestion valid, I could make a PR for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions