Files
thilalib/src/effect/schema/class/Mutable.ts
Julien Valverdé 7e90178126
Some checks failed
Lint / lint (push) Failing after 12s
Tests
2024-07-27 02:47:30 +02:00

63 lines
1.6 KiB
TypeScript

import { Schema } from "@effect/schema"
import type { Types } from "effect"
import type { StaticType } from "../../../StaticType"
import type { HasFields } from "./util"
export interface MutableClass<
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
> &
Types.Mutable<Schema.Struct.Type<Fields>>
extend<Extended>(identifier: string): <newFields extends Schema.Struct.Fields>(
fields: newFields | HasFields<newFields>,
annotations?: Schema.Annotations.Schema<Extended>,
) => MutableClass<
Extended,
Fields & newFields,
I & Schema.Struct.Encoded<newFields>,
R | Schema.Struct.Context<newFields>,
C & Schema.Struct.Constructor<newFields>,
Self,
Proto
>
}
type MutableInput<
Self,
Fields extends Schema.Struct.Fields,
I, R, C,
Inherited,
Proto
> = Omit<Schema.Class<Self, Fields, I, R, C, Inherited, Proto>,
| "extend"
| "transformOrFail"
| "transformOrFailFrom"
>
export const Mutable = <
Self,
Fields extends Schema.Struct.Fields,
I, R, C,
Inherited,
Proto
>(
self: MutableInput<Self, Fields, I, R, C, Inherited, Proto>
) => self as MutableClass<Self, Fields, I, R, C, Inherited, Proto>