This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { AbstractClass } from "type-fest"
|
import { AbstractClass, Class } from "type-fest"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import { SchemableClass } from "."
|
import { SchemableClass } from "."
|
||||||
import { StaticMembers } from "./util"
|
import { StaticMembers } from "./util"
|
||||||
@@ -43,6 +43,12 @@ export function extendSchemable<
|
|||||||
|
|
||||||
defaultValuesApplier: (defaultValues: ExtendDefaultValues) => DefaultValues,
|
defaultValuesApplier: (defaultValues: ExtendDefaultValues) => DefaultValues,
|
||||||
) {
|
) {
|
||||||
|
type ClassKind<T, Arguments extends unknown[]> = (
|
||||||
|
C extends Class<any>
|
||||||
|
? Class<T, Arguments>
|
||||||
|
: AbstractClass<T, Arguments>
|
||||||
|
)
|
||||||
|
|
||||||
const schema = schemaApplier(extend.schema)
|
const schema = schemaApplier(extend.schema)
|
||||||
const defaultValues = defaultValuesApplier(extend.defaultValues)
|
const defaultValues = defaultValuesApplier(extend.defaultValues)
|
||||||
|
|
||||||
@@ -53,7 +59,7 @@ export function extendSchemable<
|
|||||||
static readonly defaultValues = defaultValues
|
static readonly defaultValues = defaultValues
|
||||||
readonly defaultValues = defaultValues
|
readonly defaultValues = defaultValues
|
||||||
} as unknown as (
|
} as unknown as (
|
||||||
AbstractClass<
|
ClassKind<
|
||||||
Omit<C, "schema" | "defaultValues" | keyof ExtendSchemaValues> &
|
Omit<C, "schema" | "defaultValues" | keyof ExtendSchemaValues> &
|
||||||
{
|
{
|
||||||
readonly schema: typeof schema,
|
readonly schema: typeof schema,
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class Test1 {
|
|||||||
const Test2 = extendSchemable(
|
const Test2 = extendSchemable(
|
||||||
Test1,
|
Test1,
|
||||||
schema => schema.extend({ prout: z.literal("ruquier"), ruquier: z.number() }),
|
schema => schema.extend({ prout: z.literal("ruquier"), ruquier: z.number() }),
|
||||||
defaultValues => ({ prout: "ruquier" as const }),
|
() => ({ prout: "ruquier" as const }),
|
||||||
)
|
)
|
||||||
|
|
||||||
Test2.defaultValues
|
Test2.defaultValues
|
||||||
|
|||||||
Reference in New Issue
Block a user