You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it's related to "S.merge" accepting only plain object schemas (e.g no unions, no primitives):
const integerSchema = S.refine(S.number, (value, s) => {
if (value % 1 !== 0) {
throw s.fail('Must be an integer');
}
});
const nonNegativeNumberSchema = S.refine(S.number, (value, s) => {
if (value < 0) {
throw s.fail('Must be a positive number');
}
});
// have to repeat, I didn't find a way to combine integerSchema and nonNegativeNumberSchema
// e.g. S.merge() works only with objects
const nonNegativeIntegerSchema = S.refine(integerSchema, (value, s) => {
if (value < 0) {
throw s.fail('Must be a positive number');
}
});
The text was updated successfully, but these errors were encountered:
I already have plans for v9 and probably won't have time adding the feature in the near future. As for workaround I'd suggest move the refine into a reusable function:
consttoNonNegativeNumberSchema=schema=>S.refine(schema,(value,s)=>{if(value<0){throws.fail('Must be a positive number');}});constnonNegativeIntegerSchema=toNonNegativeNumberSchema(integerSchema)
I think it's related to "S.merge" accepting only plain object schemas (e.g no unions, no primitives):
The text was updated successfully, but these errors were encountered: