MutableClass work
This commit is contained in:
@@ -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">
|
||||
@@ -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>(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1 +1 @@
|
||||
export type { Static } from "./Static"
|
||||
export type { StaticType } from "./StaticType"
|
||||
|
||||
Reference in New Issue
Block a user