Files
thilalib/src/Schema/MutableClass.ts
Julien Valverdé 6b7e16ceab
All checks were successful
Lint / lint (push) Successful in 11s
Refactoring
2024-07-29 18:14:38 +02:00

55 lines
1.5 KiB
TypeScript

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