This commit is contained in:
@@ -1,42 +1,40 @@
|
||||
import { Pipe, Tuples } from "hotscript"
|
||||
import { AbstractClass, Class } from "type-fest"
|
||||
import { AbstractClass, Class, Simplify } from "type-fest"
|
||||
import { Trait, TraitClass, TraitConcreteClass } from "./Trait"
|
||||
import { TraitExpression } from "./TraitExpression"
|
||||
import { ExtendFn, ExtendPlain, SimplifyFn, StaticMembers } from "./util"
|
||||
import { ExtendPlain, StaticMembers } from "./util"
|
||||
|
||||
|
||||
export type ExtendAbstractSuper<
|
||||
SuperExpression extends TraitExpression<
|
||||
typeof TraitExpression.NullSuperclass,
|
||||
Trait<any, any, any, any>[]
|
||||
type ExtendAbstractSuper<SuperExpression, Abstract> = (
|
||||
Simplify<
|
||||
ExtendPlain<[
|
||||
...MapTraitsToOwnAbstract<
|
||||
TraitExpression.Traits<SuperExpression>
|
||||
>,
|
||||
Abstract extends object,
|
||||
> = (
|
||||
Pipe<SuperExpression, [
|
||||
TraitExpression.TraitsFn,
|
||||
Tuples.Map<Trait.OwnAbstractFn>,
|
||||
Tuples.Append<Abstract>,
|
||||
ExtendFn,
|
||||
SimplifyFn,
|
||||
Abstract,
|
||||
]>
|
||||
// ExtendPlain<[
|
||||
// ...Trait.OwnAbstract<
|
||||
// TraitExpression.Traits<SuperExpression>[number]
|
||||
// >,
|
||||
// Abstract,
|
||||
// ]>
|
||||
>
|
||||
)
|
||||
|
||||
type MapTraitsToOwnAbstract<T extends readonly any[]> = {
|
||||
[K in keyof T]: Trait.OwnAbstract<T[K]>
|
||||
}
|
||||
|
||||
|
||||
type ExtendStaticAbstractSuper<SuperExpression, StaticAbstract> = (
|
||||
Pipe<SuperExpression, [
|
||||
TraitExpression.TraitsFn,
|
||||
Tuples.Map<Trait.OwnStaticAbstractFn>,
|
||||
Tuples.Append<StaticAbstract>,
|
||||
ExtendFn,
|
||||
SimplifyFn,
|
||||
Simplify<
|
||||
ExtendPlain<[
|
||||
...MapTraitsToOwnStaticAbstract<
|
||||
TraitExpression.Traits<SuperExpression>
|
||||
>,
|
||||
StaticAbstract,
|
||||
]>
|
||||
>
|
||||
)
|
||||
|
||||
type MapTraitsToOwnStaticAbstract<T extends readonly any[]> = {
|
||||
[K in keyof T]: Trait.OwnStaticAbstract<T[K]>
|
||||
}
|
||||
|
||||
|
||||
type TraitApplierSuperTag = "@thilawyn/traitify-ts/Super"
|
||||
|
||||
|
||||
52
src/tests.ts
52
src/tests.ts
@@ -1,25 +1,7 @@
|
||||
import { Trait, TraitClass } from "./Trait"
|
||||
import { TraitClass } from "./Trait"
|
||||
import { trait } from "./TraitBuilder"
|
||||
import { Implements, ImplementsStatic, TraitExpression } from "./TraitExpression"
|
||||
import { Implements, ImplementsStatic } from "./TraitExpression"
|
||||
import { expression } from "./TraitExpressionBuilder"
|
||||
import { ExtendPlain } from "./util"
|
||||
|
||||
|
||||
type ExtendAbstractSuper<
|
||||
SuperExpression extends TraitExpression<
|
||||
typeof TraitExpression.NullSuperclass,
|
||||
Trait<any, any, any, any>[]
|
||||
>,
|
||||
Abstract extends object,
|
||||
> = (
|
||||
// ExtendPlain<[
|
||||
// ...Trait.OwnAbstract<
|
||||
// TraitExpression.Traits<SuperExpression>[number]
|
||||
// >,
|
||||
// Abstract,
|
||||
// ]>
|
||||
TraitExpression.Traits<SuperExpression>[number]
|
||||
)
|
||||
|
||||
|
||||
const PrintsHelloOnNew = trait
|
||||
@@ -53,7 +35,7 @@ const StatefulSubscription = trait
|
||||
// { _tag: "expired", expiredSince: Date }
|
||||
// )
|
||||
// }>()
|
||||
.extendAbstract(Super => class extends Super {
|
||||
.extendAbstract(Super => class StatefulSubscriptionAbstract extends Super {
|
||||
readonly isStatefulSubscription!: true
|
||||
readonly status!: (
|
||||
{ _tag: "awaitingPayment" } |
|
||||
@@ -66,7 +48,7 @@ const StatefulSubscription = trait
|
||||
type StatefulSubscriptionClass = TraitClass<typeof StatefulSubscription>
|
||||
|
||||
const ActiveStatefulSubscription = expression
|
||||
.expresses(PrintsHelloOnNew, StatefulSubscription)
|
||||
.expresses(StatefulSubscription)
|
||||
.build()
|
||||
.subtrait()
|
||||
.extendAbstract(Super => class extends Super {
|
||||
@@ -76,11 +58,6 @@ const ActiveStatefulSubscription = expression
|
||||
.build()
|
||||
|
||||
type ActiveStatefulSubscriptionClass = TraitClass<typeof ActiveStatefulSubscription>
|
||||
type Test = ExtendAbstractSuper<
|
||||
Trait.OwnSuperExpression<typeof ActiveStatefulSubscription>,
|
||||
Trait.OwnAbstract<typeof ActiveStatefulSubscription>
|
||||
>
|
||||
|
||||
|
||||
class TestSuperclass {
|
||||
// id: number = 69
|
||||
@@ -111,18 +88,13 @@ class User extends exp.extends implements Implements<typeof exp> {
|
||||
console.log(new User())
|
||||
|
||||
|
||||
// class Test1 {
|
||||
// prop1: string = "ouient"
|
||||
// prop2: bigint = 1n
|
||||
// }
|
||||
type MyTuple = [
|
||||
{ values: { gneugneu: string } },
|
||||
{ values: { ataoy: "issou" } },
|
||||
]
|
||||
|
||||
// class Test2 extends Test1 {
|
||||
// readonly prop1 = "juif"
|
||||
// prop3: number = 69
|
||||
// }
|
||||
type MapToValues<T extends { values: object }[]> = {
|
||||
[K in keyof T]: T[K]["values"]
|
||||
}
|
||||
|
||||
// type PureKeys<T, U> = {
|
||||
// [K in keyof T]: K extends keyof U ? T[K] extends U[K] ? never : K : K;
|
||||
// }[keyof T]
|
||||
|
||||
// type T = PureKeys<Test2, Test1>
|
||||
type T = MapToValues<MyTuple>
|
||||
|
||||
Reference in New Issue
Block a user