diff --git a/src/traits/ExtendableZodSchemaObject.ts b/src/traits/ExtendableZodSchemaObject.ts index b7eb3d7..d8d271b 100644 --- a/src/traits/ExtendableZodSchemaObject.ts +++ b/src/traits/ExtendableZodSchemaObject.ts @@ -1,4 +1,4 @@ -import { ImplStatic, expression } from "@thilawyn/traitify-ts" +import { ImplStatic, expression, implStaticThis } from "@thilawyn/traitify-ts" import { AbstractClass } from "type-fest" import { z } from "zod" import { Extend, StaticMembers } from "../util" @@ -18,8 +18,7 @@ export const ExtendableZodSchemaObject = < .subtrait() .implement(Super => class ExtendableZodSchemaObjectImpl extends Super { static extend< - Self extends AbstractClass - & ImplStatic, + Self extends AbstractClass, ExtendedT extends z.ZodRawShape, ExtendedCatchall extends z.ZodTypeAny, @@ -29,12 +28,13 @@ export const ExtendableZodSchemaObject = < this: Self, schemaWithDefaults: ( - schemaWithDefaults: typeof this.schemaWithDefaults + schemaWithDefaults: z.ZodObject ) => z.ZodObject, ) { + const t = implStaticThis(ExtendableZodSchemaObjectImpl, this) return expression .extends( - this as unknown as ( + t as unknown as ( AbstractClass< Omit< Extend<[InstanceType, ExtendedValues]>, @@ -45,7 +45,7 @@ export const ExtendableZodSchemaObject = < Omit, keyof ImplStatic> ) ) - .expresses(ExtendableZodSchemaObject(schemaWithDefaults(this.schemaWithDefaults))) + .expresses(ExtendableZodSchemaObject(schemaWithDefaults(t.schemaWithDefaults))) } }) .build() diff --git a/src/traits/JsonifiedZodSchemaObject.ts b/src/traits/JsonifiedZodSchemaObject.ts index 07f1a6e..7302621 100644 --- a/src/traits/JsonifiedZodSchemaObject.ts +++ b/src/traits/JsonifiedZodSchemaObject.ts @@ -1,4 +1,4 @@ -import { ImplStatic, TraitInstance, TraitStaticMembers, trait } from "@thilawyn/traitify-ts" +import { TraitInstance, TraitStaticMembers, implStaticInstantiableThis, trait } from "@thilawyn/traitify-ts" import { Class, Jsonifiable } from "type-fest" import { z } from "zod" import { parseZodSchemaEffect } from "../util" @@ -80,45 +80,39 @@ export const JsonifiedZodSchemaObject = < static jsonify< Instance extends JsonifiedValues >( - this: ( - Class & - ImplStatic - ), - values: Values, - params?: Partial, + this: Class, + values: Values, + params?: Partial, ) { - return this - .pipeSchemaIntoInstance(this.jsonifySchema) + const t = implStaticInstantiableThis(JsonifiedZodSchemaObjectImpl, this) + return t + .pipeSchemaIntoInstance(t.jsonifySchema) .parse(values, params) } static jsonifyPromise< Instance extends JsonifiedValues >( - this: ( - Class & - ImplStatic - ), - values: Values, - params?: Partial, + this: Class, + values: Values, + params?: Partial, ) { - return this - .pipeSchemaIntoInstance(this.jsonifySchema) + const t = implStaticInstantiableThis(JsonifiedZodSchemaObjectImpl, this) + return t + .pipeSchemaIntoInstance(t.jsonifySchema) .parseAsync(values, params) } static jsonifyEffect< Instance extends JsonifiedValues >( - this: ( - Class & - ImplStatic - ), - values: Values, - params?: Partial, + this: Class, + values: Values, + params?: Partial, ) { + const t = implStaticInstantiableThis(JsonifiedZodSchemaObjectImpl, this) return parseZodSchemaEffect( - this.pipeSchemaIntoInstance(this.jsonifySchema), + t.pipeSchemaIntoInstance(t.jsonifySchema), values, params, ) diff --git a/src/traits/ZodSchemaObject.ts b/src/traits/ZodSchemaObject.ts index fb479bb..4720ca3 100644 --- a/src/traits/ZodSchemaObject.ts +++ b/src/traits/ZodSchemaObject.ts @@ -1,4 +1,4 @@ -import { ImplStatic, trait } from "@thilawyn/traitify-ts" +import { implStaticInstantiableThis, trait } from "@thilawyn/traitify-ts" import { Class, HasRequiredKeys } from "type-fest" import { z } from "zod" import { parseZodSchemaEffect, stripZodObjectDefaults } from "../util" @@ -59,42 +59,36 @@ export const ZodSchemaObject = < static create< Instance extends Values >( - this: ( - Class & - ImplStatic - ), + this: Class, ...[values, params]: CreateArgs ) { - return this - .pipeSchemaIntoInstance(this.schemaWithDefaults) + const t = implStaticInstantiableThis(ZodSchemaObjectImpl, this) + return t + .pipeSchemaIntoInstance(t.schemaWithDefaults) .parse(values, params) } static createPromise< Instance extends Values >( - this: ( - Class & - ImplStatic - ), + this: Class, ...[values, params]: CreateArgs ) { - return this - .pipeSchemaIntoInstance(this.schemaWithDefaults) + const t = implStaticInstantiableThis(ZodSchemaObjectImpl, this) + return t + .pipeSchemaIntoInstance(t.schemaWithDefaults) .parseAsync(values, params) } static createEffect< Instance extends Values >( - this: ( - Class & - ImplStatic - ), + this: Class, ...[values, params]: CreateArgs ) { + const t = implStaticInstantiableThis(ZodSchemaObjectImpl, this) return parseZodSchemaEffect( - this.pipeSchemaIntoInstance(this.schemaWithDefaults), + t.pipeSchemaIntoInstance(t.schemaWithDefaults), values, params, )