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

View File

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