Open
Description
So I just found weird behavior when trying to instersect two looseObjects with optional pipes. Great combo, I know. The problem is that changing the combination sligthly (one object + one loose object, one pipe + one no pipe) makes it work.
I described all scenarios in the playground
Archive
import * as v from 'valibot';
console.log(
'both object with optional pipe',
v.safeParse(
v.intersect([
v.object({
firstName: v.optional(v.pipe(v.string(), v.toLowerCase())),
}),
v.object({
lastName: v.optional(v.pipe(v.string(), v.toUpperCase())),
}),
]),
{
firstName: 'BOB',
},
),
);
console.log(
'both looseObject with optional pipe',
v.safeParse(
v.intersect([
v.looseObject({
firstName: v.optional(v.pipe(v.string(), v.toLowerCase())),
}),
v.looseObject({
lastName: v.optional(v.pipe(v.string(), v.toUpperCase())),
}),
]),
{
firstName: 'BOB',
},
),
);
console.log(
'one object, one looseObject',
v.safeParse(
v.intersect([
v.object({
firstName: v.optional(v.pipe(v.string(), v.toLowerCase())),
}),
v.looseObject({
lastName: v.optional(v.pipe(v.string(), v.toUpperCase())),
}),
]),
{
firstName: 'BOB',
},
),
);
console.log(
'one required pipe, one optional pipe',
v.safeParse(
v.intersect([
v.looseObject({
firstName: v.pipe(v.string(), v.toLowerCase()),
}),
v.looseObject({
lastName: v.optional(v.pipe(v.string(), v.toUpperCase())),
}),
]),
{
firstName: 'BOB',
},
),
);
console.log(
'one optional string, one optional pipe',
v.safeParse(
v.intersect([
v.looseObject({
firstName: v.optional(v.string()),
}),
v.looseObject({
lastName: v.optional(v.pipe(v.string(), v.toUpperCase())),
}),
]),
{
firstName: 'BOB',
},
),
);