Refactoring
All checks were successful
Lint / lint (push) Successful in 11s

This commit is contained in:
Julien Valverdé
2024-06-16 04:12:28 +02:00
parent c5c0b5b952
commit 6fac7c7321
5 changed files with 57 additions and 50 deletions

View File

@@ -3,12 +3,11 @@ import type { Annotations, Struct } from "@effect/schema/Schema"
import type { HasFields } from "./util"
export function Class<Self>(identifier: string) {
return <Fields extends Struct.Fields>(
export const Class = S.Class as <Self>(identifier: string) =>
<Fields extends Struct.Fields>(
fieldsOr: Fields | HasFields<Fields>,
annotations?: Annotations.Schema<Self>,
) =>
S.Class<Self>(identifier)(fieldsOr, annotations) as S.Class<
) => S.Class<
Self,
Fields,
Struct.Encoded<Fields>,
@@ -17,4 +16,3 @@ export function Class<Self>(identifier: string) {
{},
{}
>
}

View File

@@ -40,12 +40,11 @@ extends Omit<
}
export function MutableClass<Self>(identifier: string) {
return <Fields extends Struct.Fields>(
export const MutableClass = S.Class as <Self>(identifier: string) =>
<Fields extends Struct.Fields>(
fieldsOr: Fields | HasFields<Fields>,
annotations?: Annotations.Schema<Self>,
) =>
S.Class<Self>(identifier)(fieldsOr, annotations) as IMutableClass<
) => IMutableClass<
Self,
Fields,
Struct.Encoded<Fields>,
@@ -54,4 +53,3 @@ export function MutableClass<Self>(identifier: string) {
{},
{}
>
}

View File

@@ -1,19 +1,15 @@
import { Schema as S } from "@effect/schema"
import type { Annotations, Struct } from "@effect/schema/Schema"
import type { Annotations, PropertySignature, Struct } from "@effect/schema/Schema"
import type { IMutableClass } from "./MutableClass"
import type { HasFields } from "./util"
export function MutableTaggedClass<Self>(identifier?: string) {
return <
Tag extends string,
export interface IMutableTaggedClass<
Self,
Tag,
Fields extends Struct.Fields,
>(
tag: Tag,
fieldsOr: Fields | HasFields<Fields>,
annotations?: Annotations.Schema<Self>,
) =>
S.TaggedClass<Self>(identifier)(tag, fieldsOr, annotations) as IMutableClass<
>
extends IMutableClass<
Self,
Fields,
Struct.Encoded<Fields>,
@@ -21,6 +17,22 @@ export function MutableTaggedClass<Self>(identifier?: string) {
Struct.Constructor<Omit<Fields, "_tag">>,
{},
{}
> &
{ readonly _tag: Tag }
>
{
readonly _tag: Tag
}
export const MutableTaggedClass = S.TaggedClass as <Self>(identifier?: string) =>
<
Tag extends string,
Fields extends Struct.Fields,
>(
tag: Tag,
fieldsOr: Fields | HasFields<Fields>,
annotations?: Annotations.Schema<Self>,
) => IMutableTaggedClass<
Self,
Tag,
{ readonly _tag: PropertySignature<":", Tag, never, ":", Tag, true, never> } & Fields
>

View File

@@ -3,18 +3,16 @@ import type { Annotations, PropertySignature, Struct } from "@effect/schema/Sche
import type { HasFields } from "./util"
export function TaggedClass<Self>(identifier?: string) {
return <
export const TaggedClass = S.TaggedClass as <Self>(identifier?: string) =>
<
Tag extends string,
Fields extends Struct.Fields,
>(
tag: Tag,
fieldsOr: Fields | HasFields<Fields>,
annotations?: Annotations.Schema<Self>,
) =>
S.TaggedClass<Self>(identifier)(tag, fieldsOr, annotations) as S.TaggedClass<
) => S.TaggedClass<
Self,
Tag,
{ readonly _tag: PropertySignature<":", Tag, never, ":", Tag, true, never> } & Fields
>
}

View File

@@ -3,4 +3,5 @@ export { MobXObservable } from "./MobXObservable"
export { MutableClass } from "./MutableClass"
export type { IMutableClass } from "./MutableClass"
export { MutableTaggedClass } from "./MutableTaggedClass"
export type { IMutableTaggedClass } from "./MutableTaggedClass"
export { TaggedClass } from "./TaggedClass"