Skip to content

Commit 666e06f

Browse files
committed
fix: vOr not trimming objects and objects with same keys but different type
1 parent 87d39dc commit 666e06f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/api/junctions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class VOr<T extends VCore<any>[]> extends VCore<ExtractI<T[number]>> {
1010
if (options.length === 0) return isValid(val)
1111
for (const opt of options) {
1212
const valid = opt.parse(val)
13-
if (valid.valid) return isValid(val)
13+
if (valid.valid) return valid
1414
}
1515
return isInvalid([err], val)
1616
}))

src/api/objects.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ export class VObject<T extends Record<string, VCore<any>>> extends VCore<G1<T>>
1313
const errors: string[] = []
1414
for (const key of keys) {
1515
if (!(key in schema)) {
16-
if (trim) delete val[key]
16+
if (trim) {
17+
try {
18+
delete val[key]
19+
} catch {/* */ }
20+
}
1721
continue
1822
}
1923
const validity = schema[key].parse(val?.[key])
2024
const errorStart = schema[key] instanceof VObject ? `${key}.` : `${key}: `
2125
if (!validity.valid) errors.push(...validity.errors.map((e) => errorStart + e))
2226
// @ts-ignore
23-
if (val) val[key] = validity.value
27+
if (val && validity.valid) val[key] = validity.value
2428
}
2529
return errors.length > 0 ? isInvalid(err ? [err] : errors, val) : isValid(val)
2630
}))

0 commit comments

Comments
 (0)