fix: object returning original elements instead of new object

This commit is contained in:
Florian Bouillon 2025-04-02 13:37:24 +02:00
parent 5851f7779a
commit bd9e0bcffe
Signed by: Florian Bouillon
GPG Key ID: 7676FF78F3BC40EC

View File

@ -27,6 +27,7 @@ export default class SchemaObject<T extends Record<string, SchemaItem> = any> ex
} }
const clone = objectClone(object) const clone = objectClone(object)
const res: ModelInfer<T> = {} as ModelInfer<T>
// loop through the childs // loop through the childs
objectLoop(this.model, (childSchema, key) => { objectLoop(this.model, (childSchema, key) => {
@ -45,7 +46,7 @@ export default class SchemaObject<T extends Record<string, SchemaItem> = any> ex
// @ts-expect-error while it's a generic we know by proof above that it's valid ! // @ts-expect-error while it's a generic we know by proof above that it's valid !
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
clone[key] = child.object res[key] = child.object
// skip rest of items if current one is invalid // skip rest of items if current one is invalid
return child.valid || !options?.fast return child.valid || !options?.fast
@ -55,7 +56,7 @@ export default class SchemaObject<T extends Record<string, SchemaItem> = any> ex
return { return {
valid: errors.length === 0, valid: errors.length === 0,
errors: errors, errors: errors,
object: clone object: res
} as ValidationResult<ModelInfer<T>> } as ValidationResult<ModelInfer<T>>
} }