This commit is contained in:
@@ -4,10 +4,20 @@ import { TraitBuilder } from "./TraitBuilder"
|
|||||||
import { Extend, StaticMembers } from "./util"
|
import { Extend, StaticMembers } from "./util"
|
||||||
|
|
||||||
|
|
||||||
|
export type TraitExpressionLike<
|
||||||
|
Superclass extends AbstractClass<object>,
|
||||||
|
Traits extends readonly Trait<any, any, any, any>[],
|
||||||
|
> = {
|
||||||
|
readonly superclass: Superclass,
|
||||||
|
readonly traits: Traits,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export class TraitExpression<
|
export class TraitExpression<
|
||||||
Superclass extends AbstractClass<object>,
|
Superclass extends AbstractClass<object>,
|
||||||
const Traits extends readonly Trait<any, any, any, any>[],
|
const Traits extends readonly Trait<any, any, any, any>[],
|
||||||
> {
|
>
|
||||||
|
implements TraitExpressionLike<Superclass, Traits> {
|
||||||
constructor(
|
constructor(
|
||||||
readonly superclass: Superclass,
|
readonly superclass: Superclass,
|
||||||
readonly traits: Traits,
|
readonly traits: Traits,
|
||||||
@@ -84,13 +94,13 @@ export namespace TraitExpression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type Superclass<T> = (
|
export type Superclass<T> = (
|
||||||
T extends TraitExpression<infer Superclass, any>
|
T extends TraitExpressionLike<infer Superclass, any>
|
||||||
? Superclass
|
? Superclass
|
||||||
: never
|
: never
|
||||||
)
|
)
|
||||||
|
|
||||||
export type Traits<T> = (
|
export type Traits<T> = (
|
||||||
T extends TraitExpression<any, infer Traits>
|
T extends TraitExpressionLike<any, infer Traits>
|
||||||
? Traits
|
? Traits
|
||||||
: never
|
: never
|
||||||
)
|
)
|
||||||
@@ -98,7 +108,7 @@ export namespace TraitExpression {
|
|||||||
|
|
||||||
|
|
||||||
export type Implements<
|
export type Implements<
|
||||||
Exp extends TraitExpression<any, readonly Trait<any, any, any, any>[]>
|
Exp extends TraitExpressionLike<any, readonly Trait<any, any, any, any>[]>
|
||||||
> = (
|
> = (
|
||||||
Simplify<
|
Simplify<
|
||||||
Extend<
|
Extend<
|
||||||
@@ -110,7 +120,7 @@ export type Implements<
|
|||||||
)
|
)
|
||||||
|
|
||||||
export type StaticImplements<
|
export type StaticImplements<
|
||||||
Exp extends TraitExpression<any, readonly Trait<any, any, any, any>[]>
|
Exp extends TraitExpressionLike<any, readonly Trait<any, any, any, any>[]>
|
||||||
> = (
|
> = (
|
||||||
Simplify<
|
Simplify<
|
||||||
Extend<
|
Extend<
|
||||||
@@ -123,7 +133,7 @@ export type StaticImplements<
|
|||||||
|
|
||||||
|
|
||||||
export type TraitExpressionClass<
|
export type TraitExpressionClass<
|
||||||
Exp extends TraitExpression<any, readonly Trait<any, any, any, any>[]>
|
Exp extends TraitExpressionLike<any, readonly Trait<any, any, any, any>[]>
|
||||||
> = (
|
> = (
|
||||||
AbstractClass<
|
AbstractClass<
|
||||||
TraitExpressionInstance<Exp>,
|
TraitExpressionInstance<Exp>,
|
||||||
@@ -133,7 +143,7 @@ export type TraitExpressionClass<
|
|||||||
)
|
)
|
||||||
|
|
||||||
export type TraitExpressionConcreteClass<
|
export type TraitExpressionConcreteClass<
|
||||||
Exp extends TraitExpression<any, readonly Trait<any, any, any, any>[]>
|
Exp extends TraitExpressionLike<any, readonly Trait<any, any, any, any>[]>
|
||||||
> = (
|
> = (
|
||||||
Class<
|
Class<
|
||||||
TraitExpressionInstance<Exp>,
|
TraitExpressionInstance<Exp>,
|
||||||
@@ -143,7 +153,7 @@ export type TraitExpressionConcreteClass<
|
|||||||
)
|
)
|
||||||
|
|
||||||
export type TraitExpressionInstance<
|
export type TraitExpressionInstance<
|
||||||
Exp extends TraitExpression<any, readonly Trait<any, any, any, any>[]>
|
Exp extends TraitExpressionLike<any, readonly Trait<any, any, any, any>[]>
|
||||||
> = (
|
> = (
|
||||||
InstanceType<TraitExpression.Superclass<Exp>> & // Keep the instance of the superclass outside of any kind of type manipulation
|
InstanceType<TraitExpression.Superclass<Exp>> & // Keep the instance of the superclass outside of any kind of type manipulation
|
||||||
// as it can accidentely remove abstract properties
|
// as it can accidentely remove abstract properties
|
||||||
@@ -155,7 +165,7 @@ export type TraitExpressionInstance<
|
|||||||
)
|
)
|
||||||
|
|
||||||
export type TraitExpressionStaticMembers<
|
export type TraitExpressionStaticMembers<
|
||||||
Exp extends TraitExpression<any, readonly Trait<any, any, any, any>[]>
|
Exp extends TraitExpressionLike<any, readonly Trait<any, any, any, any>[]>
|
||||||
> = (
|
> = (
|
||||||
Simplify<
|
Simplify<
|
||||||
Extend<[
|
Extend<[
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Schema as S } from "@effect/schema"
|
import { Schema as S } from "@effect/schema"
|
||||||
import { Simplify } from "type-fest"
|
import { Simplify } from "type-fest"
|
||||||
import { Trait, TraitTuple } from "../Trait"
|
import { Trait, TraitTuple } from "../Trait"
|
||||||
import { StaticImplements, TraitExpression } from "../TraitExpression"
|
import { StaticImplements, TraitExpressionLike } from "../TraitExpression"
|
||||||
import { Extend } from "../util"
|
import { Extend } from "../util"
|
||||||
|
|
||||||
|
|
||||||
@@ -16,6 +16,10 @@ export class EffectSchemaTraitExpression<
|
|||||||
Static extends object,
|
Static extends object,
|
||||||
|
|
||||||
const Traits extends readonly Trait<any, any, any, any>[],
|
const Traits extends readonly Trait<any, any, any, any>[],
|
||||||
|
>
|
||||||
|
implements TraitExpressionLike<
|
||||||
|
S.Class<unknown, Fields, A, I, R, C, Inherited, Proto> & Static,
|
||||||
|
Traits
|
||||||
> {
|
> {
|
||||||
constructor(
|
constructor(
|
||||||
readonly superclass: S.Class<unknown, Fields, A, I, R, C, Inherited, Proto> & Static,
|
readonly superclass: S.Class<unknown, Fields, A, I, R, C, Inherited, Proto> & Static,
|
||||||
@@ -54,9 +58,9 @@ export class EffectSchemaTraitExpression<
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
staticImplements(_target: StaticImplements<TraitExpression<typeof this.superclass, Traits>>, _context: any) {}
|
staticImplements(_target: StaticImplements<typeof this>, _context: any) {}
|
||||||
|
|
||||||
get staticImplementsStage2() {
|
get staticImplementsStage2() {
|
||||||
return (_target: StaticImplements<TraitExpression<typeof this.superclass, Traits>>) => {}
|
return (_target: StaticImplements<typeof this>) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ const userExp = effectSchemaExpression
|
|||||||
|
|
||||||
@userExp.staticImplements
|
@userExp.staticImplements
|
||||||
class User extends userExp.extends<User>() implements Implements<typeof userExp> {
|
class User extends userExp.extends<User>() implements Implements<typeof userExp> {
|
||||||
|
aMethodThatShouldBeInherited() {}
|
||||||
static aStaticMethodThatShouldBeInherited() {}
|
static aStaticMethodThatShouldBeInherited() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,3 +26,5 @@ const adminExp = effectSchemaExpression
|
|||||||
@adminExp.staticImplements
|
@adminExp.staticImplements
|
||||||
class Admin extends adminExp.extends<Admin>() implements Implements<typeof adminExp> {
|
class Admin extends adminExp.extends<Admin>() implements Implements<typeof adminExp> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new Admin({ id: 0n, role: "Admin" }).aMethodThatShouldBeInherited()
|
||||||
|
|||||||
Reference in New Issue
Block a user