diff --git a/src/effect/schema/MutableClass.ts b/src/effect/schema/MutableClass.ts index d2ee108..9eada34 100644 --- a/src/effect/schema/MutableClass.ts +++ b/src/effect/schema/MutableClass.ts @@ -6,11 +6,11 @@ import type { Static } from "../.." import type { HasFields, MissingSelfGeneric } from "./util" -type TMutableClass< +export type TMutableClass< Self, - Fields extends Struct.Fields, + Fields extends Struct.Fields, I, R, C, - Inherited extends object, + Inherited, Proto, > = ( Constructor< @@ -22,13 +22,32 @@ type TMutableClass< ConstructorParameters> > & - Static> + + Omit< + Static>, + "extend" + > & { + extend(identifier: string): ( + fields: newFields | HasFields, + annotations?: Annotations.Schema, + ) => [Extended] extends [never] + ? MissingSelfGeneric<"Base.extend"> + : TMutableClass< + Extended, + Fields & newFields, + I & Struct.Encoded, + R | Struct.Context, + C & Struct.Constructor, + Self, + Proto + > + } ) export const MutableClass = (identifier: string) => ( ( fieldsOr: Fields | HasFields, - annotations?: Annotations.Schema + annotations?: Annotations.Schema, ): ( [Self] extends [never] ? MissingSelfGeneric<"Class"> diff --git a/src/effect/schema/index.ts b/src/effect/schema/index.ts index 8c87023..d6234ea 100644 --- a/src/effect/schema/index.ts +++ b/src/effect/schema/index.ts @@ -1 +1,2 @@ export { MutableClass } from "./MutableClass" +export type { TMutableClass } from "./MutableClass" diff --git a/src/effect/schema/tests.ts b/src/effect/schema/tests.ts index 8d1ce62..adc1818 100644 --- a/src/effect/schema/tests.ts +++ b/src/effect/schema/tests.ts @@ -3,8 +3,9 @@ import { MutableClass } from "./MutableClass" class User extends MutableClass("User")({ - id: S.BigIntFromSelf + id: S.BigIntFromSelf, + role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")), }) {} -const user = new User({ id: 1n }) -user.id = 2n +const user1 = new User({ id: 1n, role: "BasicUser" }) +user1.id = 2n