0.1.2 #3
@@ -2,12 +2,12 @@ import { Trait, TraitExpression, TraitExpressionBuilder } from "@thilawyn/traiti
|
|||||||
import { AbstractClass } from "type-fest"
|
import { AbstractClass } from "type-fest"
|
||||||
import { JsonifiableObject } from "type-fest/source/jsonifiable"
|
import { JsonifiableObject } from "type-fest/source/jsonifiable"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import { ZodSchemaAbstractClass } from "./shapes/ZodSchemaClass"
|
import { ZodSchemaAbstractClass } from "../shapes/ZodSchemaClass"
|
||||||
import { DejsonifiableZodSchemaObject } from "./traits/DejsonifiableZodSchemaObject"
|
import { DejsonifiableZodSchemaObject } from "../traits/DejsonifiableZodSchemaObject"
|
||||||
import { ExtendableZodSchemaObject } from "./traits/ExtendableZodSchemaObject"
|
import { ExtendableZodSchemaObject } from "../traits/ExtendableZodSchemaObject"
|
||||||
import { InstantiableZodSchemaObject } from "./traits/InstantiableZodSchemaObject"
|
import { InstantiableZodSchemaObject } from "../traits/InstantiableZodSchemaObject"
|
||||||
import { JsonifiableZodSchemaObject } from "./traits/JsonifiableZodSchemaObject"
|
import { JsonifiableZodSchemaObject } from "../traits/JsonifiableZodSchemaObject"
|
||||||
import { StaticMembers } from "./util"
|
import { StaticMembers } from "../util"
|
||||||
|
|
||||||
|
|
||||||
export class ZodSchemaClassBuilder<
|
export class ZodSchemaClassBuilder<
|
||||||
@@ -176,3 +176,6 @@ export interface ZodSchemaClassBuilder<
|
|||||||
TraitExpressionBuilder.ExpressesFirstReturnTypeTraits<Traits, T>
|
TraitExpressionBuilder.ExpressesFirstReturnTypeTraits<Traits, T>
|
||||||
>
|
>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const zodSchemaClass = new ZodSchemaClassBuilder(TraitExpression.NullSuperclass, [])
|
||||||
56
src/tests.ts
56
src/tests.ts
@@ -1,13 +1,11 @@
|
|||||||
import { Implements, TraitExpression } from "@thilawyn/traitify-ts"
|
import { Implements } from "@thilawyn/traitify-ts"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import { ZodSchemaClassBuilder } from "./ZodSchemaClass"
|
import { zodSchemaClass } from "./builders/ZodSchemaClassBuilder"
|
||||||
import { dejsonify, jsonify } from "./schema/jsonify"
|
import { dejsonify, jsonify } from "./schema/jsonify"
|
||||||
import { ObservableZodSchemaObject } from "./traits/ObservableZodSchemaObject"
|
import { ObservableZodSchemaObject } from "./traits/ObservableZodSchemaObject"
|
||||||
import { AbstractClass, Class } from "type-fest"
|
|
||||||
|
|
||||||
|
|
||||||
const exp = new ZodSchemaClassBuilder(TraitExpression.NullSuperclass, [])
|
const exp = zodSchemaClass
|
||||||
.extends(class {})
|
|
||||||
.schema({
|
.schema({
|
||||||
schema: z.object({
|
schema: z.object({
|
||||||
/** User ID */
|
/** User ID */
|
||||||
@@ -52,32 +50,32 @@ const subInst = await SubTest.createPromise({ name: "", prout: "" })
|
|||||||
// console.log(subInst)
|
// console.log(subInst)
|
||||||
|
|
||||||
|
|
||||||
class Box<T> {
|
// class Box<T> {
|
||||||
declare ["constructor"]: typeof Box
|
// declare ["constructor"]: typeof Box
|
||||||
constructor(public value: T) {}
|
// constructor(public value: T) {}
|
||||||
|
|
||||||
otherMethod() {
|
// otherMethod() {
|
||||||
return "prout" as const
|
// return "prout" as const
|
||||||
}
|
// }
|
||||||
|
|
||||||
newBox<
|
// newBox<
|
||||||
C extends Class<I, ConstructorParameters<typeof Box>>,
|
// C extends Class<I, ConstructorParameters<typeof Box>>,
|
||||||
I extends Box<any>,
|
// I extends Box<any>,
|
||||||
T,
|
// T,
|
||||||
>(
|
// >(
|
||||||
// this: Omit<BaseClass<T>, "constructor"> & { ["constructor"]: Class<I> }
|
// // this: Omit<BaseClass<T>, "constructor"> & { ["constructor"]: Class<I> }
|
||||||
this: { ["constructor"]: C | Class<I, ConstructorParameters<typeof Box>> },
|
// this: { ["constructor"]: C | Class<I, ConstructorParameters<typeof Box>> },
|
||||||
value: T,
|
// value: T,
|
||||||
) {
|
// ) {
|
||||||
// this.otherMethod()
|
// // this.otherMethod()
|
||||||
return new this.constructor(value)
|
// return new this.constructor(value)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
class UnrelatedClass {}
|
// class UnrelatedClass {}
|
||||||
|
|
||||||
class SuperBox<T> extends Box<T> {
|
// class SuperBox<T> extends Box<T> {
|
||||||
declare ["constructor"]: typeof SuperBox
|
// declare ["constructor"]: typeof SuperBox
|
||||||
}
|
// }
|
||||||
|
|
||||||
const value = new SuperBox(69).newBox(69)
|
// const value = new SuperBox(69).newBox(69)
|
||||||
|
|||||||
Reference in New Issue
Block a user