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

z.set should enforce items uniqueness #54

Closed
zygisau opened this issue Apr 14, 2023 · 1 comment
Closed

z.set should enforce items uniqueness #54

zygisau opened this issue Apr 14, 2023 · 1 comment

Comments

@zygisau
Copy link

zygisau commented Apr 14, 2023

One of the set's valuable points is its items' uniqueness. I suggest interpreting z.set as unique items array.

For example, let's say I have a schema for filter validation. It has status property which could be an array of possible statuses.

export const statuses = z.enum([
	"draft",
	"submitted",
	"approved",
	"rejected",
	"archived",
]);

export const form = z
	.object({
		status: z.set(statuses),
	})
	.partial();

Since this is used in filtering, I would expect to be able to filter items by multiple statuses. The following snippet shows how I would expect schema to look like:

{
  // ...
  "status": {
    "type": "array",
    "uniqueItems": true, // <- this property is not present in the current output
    "items": {
      "type": "string",
      "enum": [
          "draft",
          "submitted",
          "approved",
          "rejected",
          "archived"
      ]
    }
  }
}

Let me know what You think about this feature.

@StefanTerdell
Copy link
Owner

Added in 3.20.5

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

No branches or pull requests

2 participants