ZodSchemaClassOf refactoring
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -7,7 +7,7 @@ import { Extend, StaticMembers } from "./util"
|
||||
|
||||
|
||||
export function ZodSchemaClassOf<
|
||||
Super extends AbstractClass<object, []>,
|
||||
Superclass extends AbstractClass<object, []>,
|
||||
|
||||
SchemaT extends z.ZodRawShape,
|
||||
SchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
@@ -16,42 +16,43 @@ export function ZodSchemaClassOf<
|
||||
Values extends object,
|
||||
DefaultValues extends Partial<Values>,
|
||||
>(
|
||||
of: Super,
|
||||
of: Superclass,
|
||||
|
||||
{ schema, defaultValues }: {
|
||||
schema: z.ZodObject<SchemaT, SchemaUnknownKeys, SchemaCatchall, Values, Values>
|
||||
defaultValues: DefaultValues
|
||||
},
|
||||
) {
|
||||
const exp = expression
|
||||
.extends(class extends (of as AbstractClass<object, []>) {
|
||||
static readonly schema = schema
|
||||
static readonly defaultValues = defaultValues
|
||||
class Schemas extends (of as AbstractClass<object, []>) {
|
||||
static readonly schema = schema
|
||||
static readonly defaultValues = defaultValues
|
||||
|
||||
constructor(values: Values) {
|
||||
super()
|
||||
Object.assign(this, values)
|
||||
}
|
||||
})
|
||||
constructor(values: Values) {
|
||||
super()
|
||||
Object.assign(this, values)
|
||||
}
|
||||
}
|
||||
|
||||
return expression
|
||||
.extends(Schemas as unknown as (
|
||||
AbstractClass<
|
||||
InstanceType<typeof of> &
|
||||
Extend<[
|
||||
InstanceType<typeof Schemas>,
|
||||
Values,
|
||||
]>,
|
||||
|
||||
ConstructorParameters<typeof Schemas>
|
||||
> &
|
||||
Extend<[
|
||||
StaticMembers<typeof of>,
|
||||
StaticMembers<typeof Schemas>,
|
||||
]>
|
||||
))
|
||||
.expresses(
|
||||
InstantiableZodSchemaObject,
|
||||
ExtendableZodSchemaObject,
|
||||
)
|
||||
.build()
|
||||
|
||||
return exp.extends as AbstractClass<
|
||||
InstanceType<Super> &
|
||||
Extend<[
|
||||
InstanceType<typeof exp.extends>,
|
||||
Values,
|
||||
]>,
|
||||
|
||||
ConstructorParameters<typeof exp.extends>
|
||||
> &
|
||||
Extend<[
|
||||
StaticMembers<Super>,
|
||||
StaticMembers<typeof exp.extends>,
|
||||
]>
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user