MutableClass

This commit is contained in:
Julien Valverdé
2024-06-10 03:20:01 +02:00
parent 5cba51ded4
commit 30e42b9dfd
4 changed files with 37 additions and 1 deletions

View File

@@ -0,0 +1,24 @@
import { Schema as S } from "@effect/schema"
import type { Annotations, Class, Struct } from "@effect/schema/Schema"
import type { HasFields, MissingSelfGeneric } from "./util"
export const MutableClass = <Self = never>(identifier: string) => (
<Fields extends Struct.Fields>(
fieldsOr: Fields | HasFields<Fields>,
annotations?: Annotations.Schema<Self>
): (
[Self] extends [never]
? MissingSelfGeneric<"Class">
: Class<
Self,
Fields,
Struct.Encoded<Fields>,
Struct.Context<Fields>,
Struct.Constructor<Fields>,
{},
{}
>
) =>
S.Class<Self>(identifier)(fieldsOr, annotations)
)