From cc33865e1a353a9d1cb29bdee91094877eb9c5fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Mon, 10 Jun 2024 21:03:23 +0200 Subject: [PATCH] MutableClass work --- src/{Static.ts => StaticType.ts} | 2 +- src/effect/schema/MutableClass.ts | 4 ++-- src/effect/schema/tests.ts | 10 +++++++++- src/index.ts | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) rename src/{Static.ts => StaticType.ts} (62%) diff --git a/src/Static.ts b/src/StaticType.ts similarity index 62% rename from src/Static.ts rename to src/StaticType.ts index 5eb929c..f743d3c 100644 --- a/src/Static.ts +++ b/src/StaticType.ts @@ -5,4 +5,4 @@ import type { AbstractConstructor } from "type-fest" * Represents the static members of a class. * @template C - A class. */ -export type Static> = Omit +export type StaticType> = Omit diff --git a/src/effect/schema/MutableClass.ts b/src/effect/schema/MutableClass.ts index 9eada34..3e24699 100644 --- a/src/effect/schema/MutableClass.ts +++ b/src/effect/schema/MutableClass.ts @@ -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>, + StaticType>, "extend" > & { extend(identifier: string): ( diff --git a/src/effect/schema/tests.ts b/src/effect/schema/tests.ts index adc1818..40fd657 100644 --- a/src/effect/schema/tests.ts +++ b/src/effect/schema/tests.ts @@ -8,4 +8,12 @@ class User extends MutableClass("User")({ }) {} const user1 = new User({ id: 1n, role: "BasicUser" }) -user1.id = 2n +user1.id = 1n + + +class Admin extends User.extend("Admin")({ + role: S.Literal("Admin") +}) {} + +const user2 = new Admin({ id: 2n, role: "Admin" }) +user2.id = 2n diff --git a/src/index.ts b/src/index.ts index 4e7a00c..70ad017 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1 @@ -export type { Static } from "./Static" +export type { StaticType } from "./StaticType"