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
nonEmpty validator #171
Comments
Currently I don't want to add it, as the same can be achieved with |
FWIW, published this at https://www.npmjs.com/package/valibotx |
That's great. Feel free to add it on our ecosystem page to the utilities. |
Hello @fabian-hiller, Firstly, thank you for your efforts in developing this great product. I would like to discuss the potential for a Type guard for NonEmptyArray. I noticed that the nonEmpty feature in zod is capable of inferring a Type guard for NonEmptyArray, which I find quite useful in some scenarios. To my understanding, a similar result can be achieved with the following TypeScript code: type NonEmptyArray<T> = [T, ...T[]];
export function nonEmptyArray<TItem extends BaseSchema>(item: TItem) {
return transform(array(item, [minLength(1)]), (value) => {
return value as NonEmptyArray<Output<TItem>>;
});
} However, this implementation lacks flexibility, particularly in terms of configuring additional pipe functions. I believe integrating this functionality into the core features might address this issue. What are your thoughts on this approach? Any feedback or suggestions would be greatly appreciated. Thank you for your time and consideration. |
I think that the same can be achieved with |
Also I plan to add a |
Oh, I missed the |
As a developer migrating from zod, I am missing the nonEmpty() guard, which would work like:
I realise I can achieve that with
minLength(1)
, and that I can write own plugin to reduce boilerplate. I actually did:My question is, is that something you believe could be added to the valibot distribution? I can create a PR, just wanted to ask beforehand if that makes sense.
The text was updated successfully, but these errors were encountered: