MutableClass work

This commit is contained in:
Julien Valverdé
2024-06-10 21:03:23 +02:00
parent 0b2c56be64
commit cc33865e1a
4 changed files with 13 additions and 5 deletions

View File

@@ -5,4 +5,4 @@ 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">
export type StaticType<C extends AbstractConstructor<any>> = Omit<C, "prototype">

View File

@@ -2,7 +2,7 @@ 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 "../.."
import type { StaticType } from "../.."
import type { HasFields, MissingSelfGeneric } from "./util"
@@ -24,7 +24,7 @@ export type TMutableClass<
> &
Omit<
Static<Class<Self, Fields, I, R, C, Inherited, Proto>>,
StaticType<Class<Self, Fields, I, R, C, Inherited, Proto>>,
"extend"
> & {
extend<Extended = never>(identifier: string): <newFields extends Struct.Fields>(

View File

@@ -8,4 +8,12 @@ class User extends MutableClass<User>("User")({
}) {}
const user1 = new User({ id: 1n, role: "BasicUser" })
user1.id = 2n
user1.id = 1n
class Admin extends User.extend<Admin>("Admin")({
role: S.Literal("Admin")
}) {}
const user2 = new Admin({ id: 2n, role: "Admin" })
user2.id = 2n

View File

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