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

This commit is contained in:
Julien Valverdé
2024-02-08 02:39:38 +01:00
parent ffce582e03
commit ed3f8fb643
3 changed files with 18 additions and 10 deletions

View File

@@ -1,9 +1,9 @@
import { expression } from "@thilawyn/traitify-ts"
import { NoInfer } from "effect/Types"
import { AbstractClass, Class } from "type-fest"
import { AbstractClass } from "type-fest"
import { z } from "zod"
import { InstantiableZodSchemaObject } from "./traits/InstantiableZodSchemaObject"
import { StaticMembers } from "./util"
import { Extend, StaticMembers } from "./util"
export function ZodSchemaClassOf<
@@ -36,11 +36,19 @@ export function ZodSchemaClassOf<
.expresses(InstantiableZodSchemaObject)
.build()
return exp.extends as Class<
InstanceType<typeof exp.extends> & Values,
return exp.extends as AbstractClass<
Extend<[
InstanceType<Superclass>,
InstanceType<typeof exp.extends>,
Values,
]>,
ConstructorParameters<typeof exp.extends>
> &
StaticMembers<typeof exp.extends>
Extend<[
StaticMembers<Superclass>,
StaticMembers<typeof exp.extends>,
]>
}

View File

@@ -9,10 +9,10 @@ export type CommonKeys<A, B> = Extract<keyof A, keyof B>
* Merges an inheritance tree defined by an array of types, considering overrides.
* @template T - An array of types representing the inheritance tree.
*/
export type MergeInheritanceTree<T extends readonly any[]> = (
export type Extend<T extends readonly any[]> = (
T extends [infer Super, infer Self, ...infer Rest]
? Pick<Self, CommonKeys<Self, Super>> extends Pick<Super, CommonKeys<Self, Super>>
? MergeInheritanceTree<[
? Extend<[
Omit<Super, CommonKeys<Self, Super>> & Self,
...Rest,
]>
@@ -26,10 +26,10 @@ export type MergeInheritanceTree<T extends readonly any[]> = (
* Merges an inheritance tree defined by an array of types without allowing overrides.
* @template T - An array of types representing the inheritance tree.
*/
export type MergeInheritanceTreeWithoutOverriding<T extends readonly any[]> = (
export type ExtendWithoutOverriding<T extends readonly any[]> = (
T extends [infer Super, infer Self, ...infer Rest]
? Pick<Self, CommonKeys<Self, Super>> extends Pick<Super, CommonKeys<Self, Super>>
? MergeInheritanceTreeWithoutOverriding<[
? ExtendWithoutOverriding<[
Super & Self,
...Rest,
]>

View File

@@ -1,4 +1,4 @@
export * from "./class"
export * from "./effect"
export * from "./inheritance"
export * from "./extend"
export * from "./misc"