Static & MutableClass

This commit is contained in:
Julien Valverdé
2024-06-10 04:09:43 +02:00
parent 30e42b9dfd
commit 5a74a9c449
3 changed files with 30 additions and 2 deletions

8
src/Static.ts Normal file
View File

@@ -0,0 +1,8 @@
import type { AbstractConstructor } from "type-fest"
/**
* Represents the static members of a class.
* @template C - A class.
*/
export type Static<C extends AbstractConstructor<any>> = Omit<C, "prototype">

View File

@@ -1,8 +1,28 @@
import { Schema as S } from "@effect/schema"
import type { Annotations, Class, Struct } from "@effect/schema/Schema"
import type { Mutable } from "effect/Types"
import type { Constructor } from "type-fest"
import type { Static } from "../../Static"
import type { HasFields, MissingSelfGeneric } from "./util"
type TMutableClass<
Self,
Fields extends Struct.Fields,
I, R, C,
Inherited extends object,
Proto,
> = (
Constructor<
Mutable<Struct.Type<Fields>> &
Omit<Inherited, keyof Fields>
& Proto,
ConstructorParameters<Class<Self, Fields, I, R, C, Inherited, Proto>>
> &
Static<Class<Self, Fields, I, R, C, Inherited, Proto>>
)
export const MutableClass = <Self = never>(identifier: string) => (
<Fields extends Struct.Fields>(
fieldsOr: Fields | HasFields<Fields>,
@@ -10,7 +30,7 @@ export const MutableClass = <Self = never>(identifier: string) => (
): (
[Self] extends [never]
? MissingSelfGeneric<"Class">
: Class<
: TMutableClass<
Self,
Fields,
Struct.Encoded<Fields>,

View File

@@ -1 +1 @@
export {}
export type { Static } from "./Static"