ZodSchemaObject work
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Julien Valverdé
2024-02-28 02:44:02 +01:00
parent 1956aae555
commit d204b71a05
2 changed files with 68 additions and 42 deletions

View File

@@ -36,23 +36,19 @@ export const ZodSchemaObject = <
static readonly schemaWithDefaultsValues = schemaWithDefaultValues(schema)
static instantiationSchema<
Instance extends Values
Self extends StaticMembers<ImplStaticThis<typeof ZodSchemaObject>>,
Instance extends Values,
>(
this: (
Class<Instance, [values: Values]> &
StaticMembers<ImplStaticThis<typeof ZodSchemaObject>>
)
this: Class<Instance, [values: Values]> & Self
) {
return this.schema.transform(values => new this(values))
}
static instantiationSchemaWithDefaultValues<
Instance extends Values
Self extends StaticMembers<ImplStaticThis<typeof ZodSchemaObject>>,
Instance extends Values,
>(
this: (
Class<Instance, [values: Values]> &
StaticMembers<ImplStaticThis<typeof ZodSchemaObject>>
)
this: Class<Instance, [values: Values]> & Self
) {
return this.schema.transform(values => new this(values))
}
@@ -67,7 +63,7 @@ export const ZodSchemaObject = <
),
...[values, params]: NewZodSchemaInstanceArgs<PartialValues>
) {
return this.instantiationSchema().parse(values, params)
return this.instantiationSchemaWithDefaultValues().parse(values, params)
}
})
.build()