Files
thilalib/src/effect/schema/class/MutableClass.ts
Julien Valverdé a2d7afa6cd
All checks were successful
Lint / lint (push) Successful in 11s
Package imports
2024-06-18 02:36:01 +02:00

55 lines
1.4 KiB
TypeScript

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