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