64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import { Implements, TraitAbstractMembers, expression, trait } from "."
|
|
|
|
|
|
const PrintsHelloOnNew = trait()(Super =>
|
|
class PrintsHelloOnNew extends Super {
|
|
constructor(...args: any[]) {
|
|
super(...args)
|
|
console.log("Hello!")
|
|
}
|
|
}
|
|
)
|
|
|
|
const Identifiable = <ID>() => (
|
|
trait<{ readonly id: ID }>()(Super =>
|
|
class Identifiable extends Super {
|
|
equals(el: Identifiable) {
|
|
return this.id === el.id
|
|
}
|
|
}
|
|
)
|
|
)
|
|
|
|
const StatefulSubscription = trait<{
|
|
readonly status: (
|
|
{ _tag: "awaitingPayment" } |
|
|
{ _tag: "active", activeSince: Date, expiresAt?: Date } |
|
|
{ _tag: "expired", expiredSince: Date }
|
|
)
|
|
}>()(Super =>
|
|
class StatefulSubscription extends Super {}
|
|
)
|
|
|
|
interface ActiveStatefulSubscriptionAbstractMembers extends TraitAbstractMembers<typeof StatefulSubscription> {
|
|
readonly status: { _tag: "active", activeSince: Date, expiresAt?: Date }
|
|
}
|
|
|
|
const ActiveStatefulSubscription = trait<ActiveStatefulSubscriptionAbstractMembers>()(Super =>
|
|
class ActiveStatefulSubscription extends Super {}
|
|
)
|
|
|
|
|
|
class TestSuperclass {
|
|
// id: number = 69
|
|
// static test = 69
|
|
}
|
|
|
|
|
|
const builder = expression
|
|
.extends(TestSuperclass)
|
|
.expresses(
|
|
PrintsHelloOnNew,
|
|
Identifiable<bigint>(),
|
|
// Identifiable<number>(),
|
|
)
|
|
|
|
const exp = builder.get()
|
|
type Abs = Implements<typeof exp>
|
|
|
|
class User extends exp.extends implements Implements<typeof exp> {
|
|
id: bigint = -1n
|
|
}
|
|
|
|
console.log(new User())
|