Fixed makeSchemableClassFrom
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:
@@ -1,4 +1,4 @@
|
|||||||
import { AbstractClass, Class } from "type-fest"
|
import { AbstractClass, Class as ConcreteClass } from "type-fest"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import { StaticMembers } from "./util"
|
import { StaticMembers } from "./util"
|
||||||
|
|
||||||
@@ -9,8 +9,9 @@ export function makeSchemableClassFrom<
|
|||||||
SchemaT extends z.ZodRawShape,
|
SchemaT extends z.ZodRawShape,
|
||||||
SchemaUnknownKeys extends z.UnknownKeysParam,
|
SchemaUnknownKeys extends z.UnknownKeysParam,
|
||||||
SchemaCatchall extends z.ZodTypeAny,
|
SchemaCatchall extends z.ZodTypeAny,
|
||||||
SchemaValues extends {},
|
|
||||||
DefaultValues extends Partial<SchemaValues>,
|
Values extends {},
|
||||||
|
DefaultValues extends Partial<Values>,
|
||||||
>(
|
>(
|
||||||
extend: C,
|
extend: C,
|
||||||
|
|
||||||
@@ -18,39 +19,39 @@ export function makeSchemableClassFrom<
|
|||||||
SchemaT,
|
SchemaT,
|
||||||
SchemaUnknownKeys,
|
SchemaUnknownKeys,
|
||||||
SchemaCatchall,
|
SchemaCatchall,
|
||||||
SchemaValues,
|
Values,
|
||||||
SchemaValues
|
Values
|
||||||
>,
|
>,
|
||||||
|
|
||||||
defaultValues: DefaultValues,
|
defaultValues: DefaultValues,
|
||||||
) {
|
) {
|
||||||
type ClassKind<T, Arguments extends unknown[]> = (
|
type Class<T, Arguments extends unknown[]> = (
|
||||||
C extends Class<any>
|
C extends ConcreteClass<any>
|
||||||
? Class<T, Arguments>
|
? ConcreteClass<T, Arguments>
|
||||||
: AbstractClass<T, Arguments>
|
: AbstractClass<T, Arguments>
|
||||||
)
|
)
|
||||||
|
|
||||||
return class extends (extend as unknown as Class<any, []>) {
|
return class extends (extend as unknown as ConcreteClass<any, []>) {
|
||||||
static readonly schema = schema
|
static readonly schema = schema
|
||||||
readonly schema = schema
|
readonly schema = schema
|
||||||
|
|
||||||
static readonly defaultValues = defaultValues
|
static readonly defaultValues = defaultValues
|
||||||
readonly defaultValues = defaultValues
|
readonly defaultValues = defaultValues
|
||||||
|
|
||||||
constructor(values: SchemaValues) {
|
constructor(values: Values) {
|
||||||
super()
|
super()
|
||||||
Object.assign(this, values)
|
Object.assign(this, values)
|
||||||
}
|
}
|
||||||
} as unknown as (
|
} as unknown as (
|
||||||
ClassKind<
|
Class<
|
||||||
Omit<InstanceType<C>, "schema" | "defaultValues"> &
|
Omit<InstanceType<C>, "schema" | "defaultValues"> &
|
||||||
{
|
{
|
||||||
readonly schema: typeof schema,
|
readonly schema: typeof schema,
|
||||||
readonly defaultValues: typeof defaultValues,
|
readonly defaultValues: typeof defaultValues,
|
||||||
} &
|
} &
|
||||||
SchemaValues,
|
Values,
|
||||||
|
|
||||||
Parameters<(values: SchemaValues) => void>
|
Parameters<(values: Values) => void>
|
||||||
> &
|
> &
|
||||||
|
|
||||||
Omit<StaticMembers<C>, "schema" | "defaultValues"> &
|
Omit<StaticMembers<C>, "schema" | "defaultValues"> &
|
||||||
@@ -66,15 +67,16 @@ export function makeSchemableClass<
|
|||||||
SchemaT extends z.ZodRawShape,
|
SchemaT extends z.ZodRawShape,
|
||||||
SchemaUnknownKeys extends z.UnknownKeysParam,
|
SchemaUnknownKeys extends z.UnknownKeysParam,
|
||||||
SchemaCatchall extends z.ZodTypeAny,
|
SchemaCatchall extends z.ZodTypeAny,
|
||||||
SchemaValues extends {},
|
|
||||||
DefaultValues extends Partial<SchemaValues>,
|
Values extends {},
|
||||||
|
DefaultValues extends Partial<Values>,
|
||||||
>(
|
>(
|
||||||
schema: z.ZodObject<
|
schema: z.ZodObject<
|
||||||
SchemaT,
|
SchemaT,
|
||||||
SchemaUnknownKeys,
|
SchemaUnknownKeys,
|
||||||
SchemaCatchall,
|
SchemaCatchall,
|
||||||
SchemaValues,
|
Values,
|
||||||
SchemaValues
|
Values
|
||||||
>,
|
>,
|
||||||
|
|
||||||
defaultValues: DefaultValues,
|
defaultValues: DefaultValues,
|
||||||
|
|||||||
Reference in New Issue
Block a user