Replies: 1 comment 2 replies
-
Yes, here is the fix: function requiredWhen<
TInput extends Record<string, unknown>,
TPathKeys extends v.PathKeys<TInput>,
TPathList extends Array<TPathKeys>,
TSelection extends v.DeepPickN<TInput, TPathList>,
>(
pathKeys: TPathKeys,
pathList: TPathList,
requirement: (input: TSelection) => boolean
) {
return v.forward<TInput, v.BaseIssue<unknown>>(
v.partialCheck<TInput, v.PathKeys<TInput>[], TSelection, 'field_missing'>(
[...pathList, pathKeys],
(input) => !!input[pathKeys[0]] || !requirement(input),
'field_missing'
),
pathKeys
);
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
First of all, I would like to thanks Fabian and the contributors of this awesome "Pipe rewrite" release! Valibot now meets all my needs, at the crossroads between what Zod and Yup do. Thanks!
I'm trying to reduce the amount of lines in my schemas with some helpers, but I'm having trouble with the typing.
I use a lot of
forward
andpartialCheck
in my schemas. So here is my current solution :Before :
After
Can you help me to correctly type this function? Maybe do you have any suggestion?
Thanks all
Beta Was this translation helpful? Give feedback.
All reactions