import { Implements, TraitExpression } from "@thilawyn/traitify-ts" import { z } from "zod" import { ZodSchemaClassBuilder } from "./ZodSchemaClass" import { dejsonify, jsonify } from "./schema/jsonify" import { ObservableZodSchemaObject } from "./traits/ObservableZodSchemaObject" import { AbstractClass, Class } from "type-fest" const exp = new ZodSchemaClassBuilder(TraitExpression.NullSuperclass, []) .extends(class {}) .schema({ schema: z.object({ /** User ID */ id: z.bigint(), /** Username */ name: z.string(), }), defaultValues: { id: -1n }, }) .jsonifiable({ jsonifySchema: s => s.extend({ id: jsonify.bigint(s.shape.id) }), dejsonifySchema: s => s.extend({ id: dejsonify.bigint(s.shape.id) }), }) .expresses(ObservableZodSchemaObject) .build() @exp.staticImplements class User extends exp.extends implements Implements {} User.defaultValues const inst = User.create({ id: 1n, name: "" }) // console.log(inst) const jsonifiedUser = await inst.jsonifyPromise() class SubTest extends User.extend({ schema: ({ schema }) => schema.extend({ prout: z.string() }), defaultValues: v => v, }) {} const subInst = await SubTest.createPromise({ name: "", prout: "" }) // console.log(subInst) class Box { declare ["constructor"]: typeof Box constructor(public value: T) {} otherMethod() { return "prout" as const } newBox< C extends Class>, I extends Box, T, >( // this: Omit, "constructor"> & { ["constructor"]: Class } this: { ["constructor"]: C | Class> }, value: T, ) { // this.otherMethod() return new this.constructor(value) } } class UnrelatedClass {} class SuperBox extends Box { declare ["constructor"]: typeof SuperBox } const value = new SuperBox(69).newBox(69)