MutableClass

This commit is contained in:
Julien Valverdé
2024-06-13 22:37:23 +02:00
parent c3f2ddee5d
commit 5f717cbdc2
3 changed files with 27 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
import { Schema as S } from "@effect/schema"
import type { Annotations, Class, Struct } from "@effect/schema/Schema"
import type { Mutable } from "effect/Types"
import type { StaticType } from "../../../StaticType"
import type { TMutableClass } from "./TMutableClass"
import type { HasFields } from "./util"
@@ -17,7 +17,26 @@ extends Omit<
"extend"
>
{
new(
...args: ConstructorParameters<Class<Self, Fields, I, R, C, Inherited, Proto>>
): Omit<
InstanceType<Class<Self, Fields, I, R, C, Inherited, Proto>>,
keyof Fields
> &
Mutable<Struct.Type<Fields>>
extend<Extended>(identifier: string): <newFields extends Struct.Fields>(
fields: newFields | HasFields<newFields>,
annotations?: Annotations.Schema<Extended>,
) => IMutableClass<
Extended,
Fields & newFields,
I & Struct.Encoded<newFields>,
R | Struct.Context<newFields>,
C & Struct.Constructor<newFields>,
Self,
Proto
>
}
@@ -26,7 +45,7 @@ export function MutableClass<Self>(identifier: string) {
fieldsOr: Fields | HasFields<Fields>,
annotations?: Annotations.Schema<Self>,
) =>
S.Class<Self>(identifier)(fieldsOr, annotations) as TMutableClass<
S.Class<Self>(identifier)(fieldsOr, annotations) as IMutableClass<
Self,
Fields,
Struct.Encoded<Fields>,

View File

@@ -2,5 +2,5 @@ export { Class } from "./Class"
export { MobXObservable } from "./MobXObservable"
export { Mutable } from "./Mutable"
export { MutableClass } from "./MutableClass"
export type { TMutableClass } from "./TMutableClass"
export type { IMutableClass } from "./MutableClass"
export { TaggedClass } from "./TaggedClass"

View File

@@ -8,14 +8,14 @@ import { TaggedClass } from "./TaggedClass"
const UserSuper = <Self>() => pipe(
// Class<Self>("User")({
// id: S.BigIntFromSelf,
// role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")),
// }),
TaggedClass<Self>()("User", {
MutableClass<Self>("User")({
id: S.BigIntFromSelf,
role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")),
}),
// TaggedClass<Self>()("User", {
// id: S.BigIntFromSelf,
// role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")),
// }),
// Mutable,
MobXObservable,