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

This commit is contained in:
Julien Valverdé
2024-03-17 16:52:26 +01:00
parent 2772be0be9
commit afd703b781

View File

@@ -24,6 +24,7 @@ export const ZodSchemaObject = <
static readonly schema = stripZodObjectDefaults(schemaWithDefaults)
static readonly schemaWithDefaults = schemaWithDefaults
static pipeSchemaIntoInstance<
Instance extends Values,
@@ -39,6 +40,25 @@ export const ZodSchemaObject = <
return schema.transform(values => new this(values))
}
static pipeInstanceIntoSchema<
Instance extends Values,
SchemaT extends z.ZodRawShape,
SchemaUnknownKeys extends z.UnknownKeysParam,
SchemaCatchall extends z.ZodTypeAny,
SchemaOutput,
SchemaInput extends Values,
>(
this: (
Class<Instance, [values: Values]> &
ImplStatic<typeof ZodSchemaObjectImpl>
),
schema: z.ZodObject<SchemaT, SchemaUnknownKeys, SchemaCatchall, SchemaOutput, SchemaInput>,
) {
return schema.transform(values => new this(values))
}
static create<
Instance extends Values